简体   繁体   中英

Dropzone.js - I can't upload my images

I made a controller which works correctly:

    public function gallerystore(Request $request){
    $gallery_path = 'uploads';
    $files = $request->file('gallery');
    foreach ($files as $gallery) {
      $gallery_new_name = time().$gallery->getClientOriginalName();
      $gallery->move($gallery_path, $gallery_new_name);

      $img = Image::make(public_path($gallery_path . '/' .$gallery_new_name));
      $img->resize(null, 720, function($constraint){
        $constraint->aspectRatio();
      });
    }
}

Problem is when i try use Dropzone.js . Actually when I added class dropzone into form. Laravel show me error

Invalid argument supplied for foreach().

I think adding the HTML code would help to further debug the issue. However, the error seems to be happening because the gallery parameter that you are trying to fetch is null, thus the foreach method is not able to iterate through this value.

I would suggest that the reason why this parameter is null is due to the fact that the form being submitted lacks the enctype="multipart/form-data" needed for the upload to work. Check both without the plugin and with it that this attribute is set.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM