繁体   English   中英

使用Dropzone,jQuery和php上传表单-上传多个文件时没有单独的响应

[英]Upload form with Dropzone, jQuery and php - no individual response while uploading multiple files

如前所述,如果一次上传多个文件,我的响应有问题。 例如,我上传a.jpgb.jpg 在下一步中,我上传b.jpgc.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.jpgc.jpg ,其中b.jpg已经存在。 这两个图像都获得成功图标。

现在,我上传d.jpgc.jpg (注意顺序),其中c.jpg已经存在,并且两个图像都显示错误

文件已经在那里

在此处输入图片说明

有人有同样的问题吗? 也许我在做php验证错误? 还是我必须以另一种方式处理dropzone-event-parameter(成功等)? 我尝试了successmultiplecompletemultiple等,但是没有成功。

从ProcessQueue切换为:“已解决”该问题:

self.getQueuedFiles().forEach(function(element) {
    self.processFile(element);
});

解决了其他一些问题,但可以解决。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM