将Dropzone上传的文件保存到阵列 [英] Saving dropzone uploaded files to array

查看:79
本文介绍了将Dropzone上传的文件保存到阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当文件上传时,我得到文件名的返回,但是我想将所有文件名存储在数组中并将它们附加到php形式.这是我到目前为止所拥有的.

I get return of the file names when the files are uploaded, but i want to store all of the file names in array and attach them to php form. This is what i have so far.

  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形式的.它适用于一个文件名,但仅保存最新文件名.

and then i have, this in php form. It works for one filename but only saves most current one.

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

推荐答案

您的代码是完美的.我不明白为什么它对您不起作用.

your code is perfect. I don't understand why it isn't working on your side.

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

this is the sample code ... which is running for me.

        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 + '">'));
                }
            }
        };

但是,这仅在您一张一张地上传图片的情况下有效..否则,如果您一次上传多张图片,则必须尝试循环播放.我希望你能理解.

But this only work if you are uploading images one by one.. else you have to try loop if you are uploading mulitple images at the time. I hope you understand.

这篇关于将Dropzone上传的文件保存到阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆