0

This is my html code

{{Form::open(array('route'=>'admins.changePicture', 'class' => 'mainInformationContrainer', 'method'=> 'POST', 'file' => true)) }}
<ul>
    <li>
        <label>Picture</label>
        <div class="oneInfo thumbnail">
            <img src="#" id="imageID">
        </div>
    </li>
    <li>
        <label>.</label>
        <div class="oneInfo" style="width: 200px; overflow: hidden">
            <span class="spanForFileInput">

                <input type="button" class="selectImage" value="Select Image" />
                <input type="file" value="Select Image" id="imgInp"/>
            </span>
            <input type="submit"  />
        </div>
    </li>
    <li>
        <label></label>
        <div class="oneInfo">

        </div>
    </li>
</ul>
{{ Form::close() }}

and in my controller I do this

public function changePicture(){
    $image = Input::file('imageID');echo $image; exit;
}

I got an empty result

my question is how to catch the image in the controller and if you how to save it to my sql database? my column is from type longblob

Anastasie Laurent
  • 1,169
  • 6
  • 23
  • 35

1 Answers1

1

You get an empty result because you have this:

<input type="file" value="Select Image" id="imgInp"/>

There is no name but only an id so you need to add a name in your input like this:

<input type="file" value="Select Image" id="imgInp" name="imgInp" />

Now you may use this:

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

Save the data in the database:

$image = base64_encode(file_get_contents(Input::file('imgInp')->getRealPath()));

Now insert the $image in your database field and to show it in your view just use:

// Assumed the field in the database is imageField
$imgdata = base64_decode($model->imageField);
$f = finfo_open();
$ext = finfo_buffer($f, $model->imageField, FILEINFO_MIME_TYPE);
echo '<img src="data:image/' . $ext . ';base64,' . $model->imageField . '" />';
The Alpha
  • 143,660
  • 29
  • 287
  • 307
  • Hello Mr. Hope you good today. could you check my question please http://stackoverflow.com/questions/24465200/laravel-how-to-update-a-field-to-a-database – Anastasie Laurent Jun 28 '14 at 09:07
  • Hello, could you help me here please http://stackoverflow.com/questions/24843547/laravel-set-disabled-select-option appreciate the efforts – Anastasie Laurent Jul 19 '14 at 18:35