2016-11-24 64 views
1

當文件上傳時,我得到文件名的返回,但是我想將所有文件名存儲在數組中,並將它們附加到php表單中。這是我迄今爲止。將dropzone上傳的文件保存到數組

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')) !!} 

回答

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

但如果你上傳圖片逐一..否則你必須嘗試循環,如果你在當時上傳多張圖片這只是工作。我希望你明白。