Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Arslan's avatar

Image source not readable

Image source not readable ?

I am using Laravel 5.2 And Having problem with image Uploader.

Here is my code

 <input id="file-2" type="file" multiple name="images[]">

And Function

if(Input::hasFile('images'))
        {
            $image = Image::make(Request::file('images'));
            $random = time().rand(00000,99999);
            $orignal = "orignal-".$random;
            $thumb = "thumb-".$random;
            $path = "uploads/gallery/";
            $image->encode('jpg');
            $save_org = $image->save($path.$orignal.".jpg");
            $image->resize(300,200, function ($constraint) {
                 $constraint->aspectRatio();
                 $constraint->upsize();
            });
            $save_thumb = $image->save($path.$thumb.".jpg");
            if($save_org)
            {
                $products->screenshots = implode(",",$orignal.".jpg");
            }
        }

Giving Error . But if a upload singlr image its work perfectly

0 likes
4 replies
moharrum's avatar

If you're uploading images, you have to loop through $request->file('images'),

if(Input::hasFile('images')) {
    foreach (Input::file('images') as $uploadedImage) {
        $image = Image::make($uploadedImage);
        $random = time() . rand(00000, 99999);
        $orignal = "orignal-" . $random;
        $thumb = "thumb-" . $random;
        $path = "uploads/gallery/";
        $image->encode('jpg');
        $save_org = $image->save($path . $orignal . ".jpg");
        $image->resize(300, 200, null, function ($constraint) {
            $constraint->aspectRatio();
            $constraint->upsize();
        });
        $save_thumb = $image->save($path . $thumb . ".jpg");
        if ($save_org) {
            $products->screenshots = implode(",", $orignal . ".jpg");
        }
    }
}
1 like
Snapey's avatar

You have multiple specified so you will receive an array of images.

You need to foreach over the array, saving each individually.

1 like
Arslan's avatar

@moharrum thanks for your valubale time its works fine. But there is an issue. i want to save all images in Comma Seperate in one field.. But its give me error of implode(): Invalid arguments passed Hoe can i fix it.

Snapey's avatar

implode is for an array.

You should concatenate the names of the images to the end of a string and then save the string once you have processed all the images.

Please or to participate in this conversation.