Storing images in your database is unadvised. Instead, store the path to the image in your disk, or URL where the image is located.
May 22, 2015
6
Level 2
Simple Logic
I have a table with 5 image fields like
img_1
img_2
img_3
img_4
img_5
how can i upload images in these fields. ? I have to make sperate browse buttons for that 5 fields or there is any better way
Level 3
@Alizey instead of using 5 seprate fields i suggest you to make a array of all images :D
<input name="file[]" type="file" id="exampleInputFile" multiple>
SomeFunction
Get that Files
$file = Request::file('file');
$arr = '';
$i=1;
foreach($file as $files)
{
$image_name = time()."-".$files->getClientOriginalName();
$files->move('uploads', $image_name);
$image = Image::make(sprintf('uploads/%s', $image_name))->resize(200, 200)->save();
if($i==1)
{
$arr = array($image_name);
}
else
{
array_push($arr,$image_name);
}
$i++;
}
//Store that to json array like
$arr = json_encode($arr);
//and finaly store that array in your DB field
$someVariable->images = $arr;
$someVariable->save();
I hope its works :D
2 likes
Please or to participate in this conversation.