将dropzone上传的文件保存到阵列

时间:2016-11-24 10:24:07

标签: php laravel dropzone.js

我上传文件后返回文件名,但我想将所有文件名存储在数组中并将它们附加到php表单。这就是我到目前为止所拥有的。

  this.on("success", function(file, res) {
        console.log(res.path);
        file.newFileName = res;
      $path = res.path;

       // Create a hidden input to submit to the server:
    $("#image").append($('<input type="hidden" ' +'name="files[]" ' +'value="' + res.path + '">'));

      });

然后我有,这是PHP形式。它适用于一个文件名,但只保存最新的文件名。

{!! Form::hidden('image', '', array('id' => 'user-image')) !!}

1 个答案:

答案 0 :(得分:0)

你的代码很完美。我不明白为什么它不适合你。

这是示例代码...正在为我运行。

        Dropzone.options.myDropzone = {
            paramName: "product_image",
            addRemoveLinks: true,
            success: function (file, response) {
                var obj = JSON.parse(response);
                file.name = obj.file_name;
                if (obj.error == true) {
                    file.previewElement.classList.add("dz-error");
                } else {
                    file.previewElement.classList.add("dz-success");
                    $("#my-dropzone").append($('<input type="hidden" ' + 'name="product_images[]" ' + 'value="' + obj.file_name + '">'));
                }
            }
        };

但是这只有在你逐个上传图片的情况下才有用。否则你必须尝试循环,如果你当时正在上传多个图像。我希望你明白。

相关问题