如何使用dropzone.js上传多个文件?
我的问题是当我拖动&那个时候删除多个文件,每个图像称为微粒ajax.我希望多个文件上传时间只有一个ajax调用.
My problem is when i drag & drop multiple file that time each image called particulate ajax. I want to multiple file upload time only one ajax call.
我要选择单个文件拖放在另一个文件拖放后将其放到dropzone中将其删除以免替换为第一个文件,我需要主题和单击按钮,一次将其保存在一次Ajax调用的文件夹中.
I want to choose single one file drag & drop it in dropzone after another file drag & drop it so not replace file to first one I need both of theme and click on button that time save in folder at one time ajax call.
这是我的代码
HTML文件
<link href="https://cdnjs.cloudflare.com/ajax/libs/dropzone/4.0.1/min/dropzone.min.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/dropzone/4.2.0/min/dropzone.min.js"></script>
<div class="row">
<form action="route.php?actionPresubmission=loanPreSubmission" class="form-horizontal dropzone" id="imageform">
</form>
</div>
route.php
$uploadDir = 'upload';
if (!empty($_FILES)) {
$tmpFile = $_FILES['file']['tmp_name'];
$filename = $uploadDir.'/'.time().'-'. $_FILES['file']['name'];
move_uploaded_file($tmpFile,$filename);
}
谢谢
解释这个问题,我想您想通过一个呼叫上传多个文件.为此,您需要停止默认情况下为true的autoProcessQueue
Interpreting the question, I think you want to upload multiple files through one call. For that, you need to stop autoProcessQueue which is true by default
脚本:
Dropzone.options.myDropzone = {
autoProcessQueue: false, //This stops auto processing
acceptedFiles:".png,.jpg", //Change it according to your requirement.
init: function(){
var submit = document.querySelector('#submit');
mydropzone = this;
submit.addEventListener("click", function(){
mydropzone.processQueue();
});
this.on("success", function(file,response){
alert(response);
});
},
};
HTML :
<form action="upload.php" class="dropzone" id="myDropzone"></form>
<div>
<button type="button" class="btn btn-info" id="submit">Upload</button>
</div>
PHP
<?php
$folderName = 'upload/';
if(!empty($_FILES))
{
$file = $_FILES['file']['tmp_name'];
$fileLocation = $folderName . $_FILES['file']['name'];
move_uploaded_file($file,$fileLocation);
} ?>
希望这对您有所帮助:)
Hope this helped you :)