【发布时间】:2018-09-05 22:24:47
【问题描述】:
如上所述,如果我一次上传多个文件,我的响应会出现问题。
比如我上传a.jpg和b.jpg。
下一步,我上传b.jpg 和c.jpg。
我的 PHP 脚本检查名称的重复性并在 b.jpg 中找到一个,但作为响应,我将每个图像都标记为
错误 - 文件已经存在。
我无法单独区分回复。
我通过 jquery 初始化我的 dropzone:
myDropZone = $("#dropzone").dropzone({
autoProcessQueue: false,
uploadMultiple: true,
xx: xx
init:function(){
var self = this;
// check error and some other states
self.on("error", function (file, response) {
console.log("error: "+file);
console.log("error-response: "+response);
}
// set process
$("#actions .start").click (function(file){
self.processQueue();
}
}
});
我使用uploadMultiple 进行多个文件上传,我禁用了autoprocess 并将函数processQueue() 绑定到我喜欢的按钮。
到目前为止一切顺利。
不,我有我的 php 脚本处理数据。由于uploadMultiple 参数,它应该被调用一次。
if (!empty($_FILES)) {
// resort array for easy processing
for($i = 0 ;$i < count($_FILES['file']['name']) ; $i++) {
$fileArrays[] = array_column ( $_FILES['file'], $i);
}
foreach($fileArrays as $file) {
$upload = array();
if(file_exists($file[0])) {
$upload[] = "File already there.";
}
// some other validations...
}
if(empty($upload)) {
//move_uploaded_file()
http_response_code(200);
} else {
print_r($upload);
http_response_code(404);
}
但现在所有上传都会得到所有响应,无论它们是否真实。
例如,我上传了b.jpg 和c.jpg,其中b.jpg 已经存在。两张图片都有成功图标。
现在我上传d.jpg 和c.jpg(注意顺序),其中c.jpg 已经存在并且两个图像都显示错误
文件已经存在
有人对回复有同样的问题吗?
也许我做错了 php-validation?
还是我必须以另一种方式处理 dropzone-event-parameter(成功等)?我试过successmultiple、completemultiple等,但没有成功。
【问题讨论】:
标签: php jquery file-upload upload dropzone.js