我已经实现了上传图片到后台,就是不知道怎么获取后台上传的图片名,后台是用时间戳的,不知道这样图片文件大的话会不会有延时,延时的话前台用时间戳也不太好吧,希望能人帮我完善下代码
HTML
<input type="file" id="upfile" oninput="myFunction()">
<script>
function uploadPhoto() {
$("#upfile").click();
}
function myFunction() {
var fd = new FormData();
fd.append("upload", 1);
fd.append("upfile", $("#upfile").get(0).files[0]);
$.ajax({
url: "content/templates/Joe/inc/doupload.php",
type: "POST",
processData: false,
contentType: false,
data: fd,
success: function(d) {
console.log(d);
}
});
}
</script>
PHP
<?php
if (isset($_POST['upload'])) {
var_dump($_FILES);
move_uploaded_file($_FILES['upfile']['tmp_name'], 'up_tmp/'.time().'.png');
exit;
}
?>