Dropzone 中的多个名称属性

Multiple name attributes in Dropzone

美好的一天,

我正在尝试在 Laravel 项目中实施 Dropzone。有人可以建议我如何向 Dropzone 脚本添加多个名称属性,以便在不同位置上传图像并将图像名称存储在数据库中吗?请在下面找到代码。将不胜感激。

查看文件:

<script type="text/javascript">
       Dropzone.options.dropzone =
       {
           maxFilesize: 10,
           renameFile: function (file) {
               var dt = new Date();
               var time = dt.getTime();
               return time + file.name;
           },
           acceptedFiles: ".jpeg,.jpg,.png,.gif",
           addRemoveLinks: true,
           timeout: 60000,
           success: function (file, response) {
               console.log(response);
           },
           error: function (file, response) {
               return false;
           }
       };
   </script>

控制器:

 public function store(Request $request)
   {

// Upload image 1
       $image1 = $request->file('file1');
       $avatarName = $image1->getClientOriginalName();

       $image1->move(storage_path('app/public/images/image1'),$avatarName);
       $imageUpload = new Image();
       $imageUpload->filename = $avatarName;
       $imageUpload->save();
       return response()->json(['success'=>$avatarName]);

// Upload image 2
       $image2 = $request->file('file2');
       $avatarName = $image2->getClientOriginalName();

       $image2->move(storage_path('app/public/images/image2'),$avatarName);
       $imageUpload = new Image();
       $imageUpload->filename = $avatarName;
       $imageUpload->save();
       return response()->json(['success'=>$avatarName]);

//Save image names in the database   
       $user = Auth::user();
       $property = new Property;

       $property->user_id = auth()->user()->id;
       $property->image1 = $image1;
       $property->image2 = $image2;

       $user->save();
       $property->save();
       return redirect('/users/listings')->with('success', 'Listing has been created.');   
   }
}

每个拖放区只有 1 个从输入文件标签中获取的名称,因此您需要 2 个拖放区。