Ifrit's avatar
Level 2

Getting laravel to save images

I'm using dropzone.js to create a drag and drop section where I can save my images I've managed to be able to have it upload to the correct folder but the issue I'm having is that I'm not able to print my image when I user Print_r. When I use print_r I get a blank array.

My Controller

public function store(){
        $input = Input::all();

         $file = Input::file();

         echo "<PRE>";
        print_r($file);
        die();
   }

my create page

<!-- This gets the admin template from app/modules/templates/views -->
@extends('templates::layouts.admin')
<!-- This inserts the content below into the template -->
@section('content')
{{-- {{ Html::script('js/admin/menu.js') }} --}}
    {{ Form::open(array('route' => 'admin.menus.store', 'class' => 'add-form')) }}
        <div class="form">
            <div class="title_input">
                <div>
                    {{ Form::label('title', 'Title') }}
                </div>
                <div>
                    {{ Form::text('title','', array('id' => 'title', "class" => "form-control")) }}
                </div>
            </div>

            <div class="dropzone" id="my-dropzone" name="mainFileUploader">
                <div class="fallback">
                    <input name="file" type="file" multiple />
                </div>
            </div>
            
            <script>
                Dropzone.options.myDropzone = {
                    url: "{{ asset("uploads/upload.php?target=menu_images") }}",
                };
            </script>

            <div class="submit_button">
                <div>
                    {{ Form::submit('Submit', array("class" => "btn btn-info submit", "role" => "button")) }}
                </div>
            </div>
        </div>
    {{ Form::close() }}
@stop
0 likes
5 replies
jlrdw's avatar

Check GitHub for package that will print the images.

Ifrit's avatar
Level 2

Sorry maybe I didn't explain properly. I'm trying to save my images into the database but I'm having a problem doing that.

phpMick's avatar

I do it like this:

 $tmpFileName = Input::file('fileDrawing');
$file = file_get_contents($tmpFileName);
$drawing->bitmap = $file;
$drawing->save();

Mick

seanwu's avatar

How about saving the image into file system and store the path into database?

RonB1985's avatar
{{ Form::open(array('route' => 'admin.menus.store', 'class' => 'add-form')) }}

It is missing:

'files' => 'true'

Change it to:

{{ Form::open(array('route' => 'admin.menus.store', 'class' => 'add-form', 'files' => 'true')) }}

For more information:

http://laravel-recipes.com/recipes/124/opening-a-new-html-form

Specifying file uploads

If you pass a 'files' => true as one of the array arguments, the form will become suitable for file uploads.

{{ Form::open(array('files' => true)) }}
The form now has the enctype="multipart/form-data" attribute.
<form method="POST" action="http://currenturl" accept-charset="UTF-8"
  enctype="multipart/form-data">
<input name="_token" type="hidden" value="somelongrandom string">
1 like

Please or to participate in this conversation.