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()
]);
}
}
Can you show the form as well?
@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>
@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 Chief.... Even I tried the link and found that it shows only the last image ?
@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
@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 ?
@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
@Sinnbeck Thanks chief !! it was a timely help for me :). Was struggling for the last 2 hours lolzzz
@Sinnbeck Very impressive chief !!! keep rocking !
Please sign in or create an account to participate in this conversation.