Ad

Dropzone.js With Laravel Get 500 (Internal Server Error)

- 1 answer

I try to upload image with dropzonejs library. I have follow the documentation on dropzone but I get Internal Server Error.

html:

<form action="http://localhost/visitingcy/public/management/create-thing"
      class="dropzone"
      id="my-awesome-dropzone">
    <input type="hidden" name="_token" value="{{ csrf_token() }}"/>
</form>

Laravel php code:

        if ($request->hasFile('file')) {
        $getImages = $request->input('file');
        $count = 0;
        $images = array();
        foreach ($getImages as $img) {
            $imageURL = str_slug($newThing->title) . '.' . $img->getClientOriginalExtension();
            $checkForDuplicate = DB::table('things_images')->where('url', '=', $imageURL)->get();

            while (!empty($checkForDuplicate)) {
                $imageURL = str_slug($newThing->title) . $count . '.' . $img->getClientOriginalExtension();
                $checkForDuplicate = DB::table('things_images')->where('url', '=', $imageURL)->get();
                $count++;
            }
            $images[] = ThingImage::create(['url' => $imageURL]);

            //save file to public directory
            $img->move(base_path() . '/public/img/thing/gallery/', $imageURL);
        }
        return $images;
    } else {
        dd('there isnt file');
    }
Ad

Answer

I found the problem. I had used foreach but the dropzone upload each file individually so it doesn't need. The 500 error from the console is because I have another feature in my controller that has issue.

Ad
source: stackoverflow.com
Ad