samedi 25 avril 2015

Laravel 5 override summernote Image upload


I want to override image upload in summernote with laravel 5 method ajax, but I cant get it to work.

Here's my php method

public function ajaxImage()
{
    $file = Input::file('image');
    $destinationPath = public_path();
    $filename = $file->getClientOriginalName();
    if(Input::file('image')->move($destinationPath, $filename)) {
        echo $destinationPath.$filename;
    }
}

and here's my jquery code:

$(document).ready(function(){
            $('#description').summernote({
                height: 300,

                onImageUpload: function(files, editor, welEditable) {
                    sendFile(files[0], editor, welEditable);
                }
            });
            function sendFile(file, editor, welEditable) {
                var  data = new FormData();
                data.append("file", file);
                var url = '/articles/ajaximage';
                $.ajax({
                    data: data,
                    type: "POST",
                    url: url,
                    cache: false,
                    contentType: false,
                    processData: false,
                    success: function(url) {
                        alert('Success');
                        editor.insertImage(welEditable, url);
                    }
                });
            }
        });

and i get an error in the console of:

POST http://ift.tt/1HCJ622 500 (Internal Server Error)


Aucun commentaire:

Enregistrer un commentaire