我正在尝试使用Dropzone js和PHP上传图像,它可以工作,但我想将文件上传名称保存在PHP变量中,但它失败了。
form.php的
<form method="post" action="new_is_add.php" id="form_first" enctype="multipart/form-data">
<div class="form-group">
<div id="my-dropzone" class="dropzone">
<div class="dz-message" data-dz-message>
<span>
Max 2 files
</span>
</div>
</div>
</div>
<div class="text-center">
<button type="submit" name="submit_new" id="submit_new" class="btn btn-primary">Valider</button>
</div>
</form>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dropzone.js"></script>
<script type="text/javascript" src="script.js"></script>
的script.js
var theDate = new Date().getTime();
Dropzone.autoDiscover = false;
var myDropzone = new Dropzone("div#my-dropzone", {
paramName: "file",
acceptedFiles: 'image/*',
maxFiles: 2,
maxFilesize: 2, // MB
renameFilename: function (filename) {
return theDate + '_' + filename;
},
url: "new_is_add.php",
autoProcessQueue: false,
});
$('#submit_new').click(function(){
myDropzone.processQueue();
});
new_is_add.php
if(!empty($_FILES)){
$targetDir = "uploads/";
$fileName = $_FILES['file']['name'];
$targetFile = $targetDir.$fileName;
move_uploaded_file($_FILES['file']['tmp_name'],$targetFile);
echo $_FILES['file']['name'];
}
我的$_FILES['file']['name']
为空,我该如何获取文件名?