【问题标题】:Upload form with Dropzone, jQuery and php - no individual response while uploading multiple files使用 Dropzone、jQuery 和 php 上传表单 - 上传多个文件时没有单独的响应
【发布时间】:2018-09-05 22:24:47
【问题描述】:

如上所述,如果我一次上传多个文件,我的响应会出现问题。 比如我上传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-validation? 还是我必须以另一种方式处理 dropzone-event-parameter(成功等)?我试过successmultiplecompletemultiple等,但没有成功。

【问题讨论】:

    标签: php jquery file-upload upload dropzone.js


    【解决方案1】:

    通过从 ProcessQueue 切换到“解决”它:

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

    它带来了一些其他问题,但它们是可以解决的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-06-29
      • 2021-12-07
      相关资源
      最近更新 更多