AiD
AiD

Reputation: 1007

How to use Dropzone with laravel 4.2

i want to incorporate 'Dropzone' to my website with Laravel 4.2 , I found an example in their official website here .

But when I add it to my form, the form changes behavior and I can't processed the image in the controller. could you give me an basic example of dropzone with Laravel 4.2?

Upvotes: 1

Views: 753

Answers (2)

AiD
AiD

Reputation: 1007

This is my View code :

{{ Form::open(array('files'=> true  , 'method' => 'post' ,'route' => array('article.create', Route::current()->getParameter('lang')))) }}

                  <div class="fallback" id = "dropzone" >
                    <input name="file" type="file" multiple />
                  </div>

        {{ Form::submit(Lang::get('messages.create') , array('class' => 'btn btn-default custom-submit')) }}

    {{ Form::close() }}
<script>
var myDropzone = new Dropzone("div#dropzone", {
    url: "{{URL::route('compose-attachment')}}",
    //clickable: "#yourSubmitButton",
    paramName: "file",
    addRemoveLinks: true,
    init: function() {

                });
            });
    }
});
</script>

Routes :

Route::post('/compose-attachment', array( 'as' => 'postMsgAttachment','uses' => 'ArticleController@getPostAttachment'));

Controller :

public function getPostAttachment(){
        $file = Input::file('file');
        return var_dump($file);
    }

Upvotes: 0

Michel
Michel

Reputation: 1165

<script>
                        var myDropzone = new Dropzone("div#dropzone", {
                            url: "{{URL::route('compose-attachment')}}",
                            //clickable: "#yourSubmitButton",
                            paramName: "file",
                            addRemoveLinks: true,
                            init: function() {

                                        });
                                    });
                            }
                        });
                    </script>

Route:

Route::post('/compose-attachment', array( 'as' => 'postMsgAttachment','uses' => 'UserController@getPostAttachment'));

Controller:

public function getPostAttachment(){


 $file = Input::file('file');
 $destinationPath =  public_path().'/uploads';
 $time = time();

 $filename = $time."-".$file->getClientOriginalName(); 
 $upload_success = Input::file('file')->move($destinationPath, $filename);
 }

Upvotes: 2

Related Questions