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
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");
}
}
}
You have multiple specified so you will receive an array of images.
You need to foreach over the array, saving each individually.
@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.
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 sign in or create an account to participate in this conversation.