Alizey's avatar

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

0 likes
6 replies
JohnRivs's avatar

Storing images in your database is unadvised. Instead, store the path to the image in your disk, or URL where the image is located.

2 likes
wayneDK's avatar

I often read posts that advise not to store images in the DB, however, assuming the images are fairly small, say a couple 200Kb or less, what's the real issue with this, given text content can easily get this big can can comfortably managed within the DB.

Given mysql has the 'largeblob' field type, what can't this be used for image management in the DB, for small images at least?

Storing everything in the DB makes backup and content management much easier?

2 likes
SCC's avatar

Files are more easily managed within the file system rather than the DB, yes 200kb or less may not seem much but 100 images later and 20mb on your database and you will notice the difference.

To upload multiple files use a from element something like this

{!! Form::file('images[]', array('multiple'=>true)) !!}

Note you are using an array to capture multiple items, of course you then need to process each of them as required, resize, give a random name, save and so on.

1 like
Sonu's avatar
Sonu
Best Answer
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.