Juluri Vinay Juluri Vinay - 1 year ago 134
PHP Question

how to save multiple images in table using laravel php

Hi please help me am new to laravel
I want to store multiple images in table... With this code am unable to save.

Help me for this..

Here in my View

{{Form::open(array('url'=>'businessdirectory/business', 'files'=>true))}}
{{Form::label('image','Upload Image')}}

<div class="form-group">{{Form::file('image[]',array('multiple'=>true))}}


In my Controller

$image = Input::file('image');

foreach($image as $img) {
$destination = 'images';
$filename = $img->getClientOriginalName();
$path = 'images/'.$filename;
$uploadSuccess = $img->move($destination,$filename);
$business = new Business();
$business->image = $path;

Answer Source

It's not advisable to store images on database. Just save the path of the images instead.

If you really need to store image on db. Make sure you set the column to blob as it need more space. Then, get the image content and type, then save it.

$image = fopen($image_path, 'rb');
// or
$image = file_get_contents($image_path);

$business = new Business;
$business->image = $image;
$business->imageType = "image/gif"; // 

// ...
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download