FounderStartup's avatar

Multi Image Upload not working

Following is my controller. It is saving only one image. What I am missing ?

Controller

            if ($request->file('imageFile')) {

                    $images = $request->file('imageFile');
                    foreach ($images as $img) {
                        $make_name = hexdec(uniqid()).'.'.$img->getClientOriginalExtension();
                        Image::make($img)->save('upload/listings/'.$make_name);

                    ProjectMultipleImage::insert([
                        'image' => $make_name,
                        'projectid' => $projectid,
                        'created_at' => Carbon::now()
                        ]);
                    }
            }
0 likes
12 replies
FounderStartup's avatar

@Sinnbeck

<div class="user-image mb-3 text-center">
                        <div class="imgPreview"> </div>
                    </div>
                    <label class="form-label">Upload Multiple Project Image</label>

                    <div class="custom-file">
                        <input type="file" name="imageFile[]" class="custom-file-input" id="files" multiple >
                        <label class="custom-file-label" for="images">Choose image</label>
                    </div>
FounderStartup's avatar

@Sinnbeck

rray:1 [▼ // app/Http/Controllers/Backend/ProjectsController.php:141 0 => Illuminate\Http\UploadedFile {#1705 ▼ -test: false -originalName: "The Best Place for Real Estate Brokers to Do Deals, Network, and Grow (LinkedIn Background Photo) (Twitter Header) (YouTube Banner)-3.png" -mimeType: "image/png" -error: 0 #hashName: null path: "/private/var/folders/gt/ct_sxm392t7glgknbc225yr40000gn/T" filename: "phpepuCAj" basename: "phpepuCAj" pathname: "/private/var/folders/gt/ct_sxm392t7glgknbc225yr40000gn/T/phpepuCAj" extension: "" realPath: "/private/var/folders/gt/ct_sxm392t7glgknbc225yr40000gn/T/phpepuCAj" aTime: 2022-11-21 11:56:32 mTime: 2022-11-21 11:56:32 cTime: 2022-11-21 11:56:32 inode: 12924758030 size: 642888 perms: 0100600 owner: 501 group: 20 type: "file" writable: true readable: true executable: false file: true dir: false link: false } ]

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@FounderStartup Works for me. Any chance you are clicking Choose files, selecting 1 image, clicking Choose files again, and selecting another file ? You need to select all files the first time you open the dialog

1 like
FounderStartup's avatar

@Sinnbeck OMG lolzzzzzz I was not selecting all at the same time . Now it worked. But isn't it the wrong way to select multiple images ?

Sinnbeck's avatar

@FounderStartup Thats how the built in file selector in the browser works. If you want it to work like you were doing, use a javascript plugin like dropzone or similar

1 like

Please or to participate in this conversation.