php - SOLVED! Laravel 5 override summernote Image upload -
i want override image upload in summernote laravel 5 method ajax, cant work.
here's 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 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 error in console of:
post http://marcus.dev/articles/ajaximage 500 (internal server error)
i found out how.. "tokenmismatchexception in verifycsrftoken" problem.
source: http://laravel.io/forum/01-30-2015-laravel5-tokenmismatchexception-in-verifycsrftoken
i added in header of main view:
<meta name="csrf-token" content="{{ csrf_token() }}" />
and in script before document.ready
$.ajaxsetup({ headers: { 'x-csrf-token': $('meta[name="csrf-token"]').attr('content') } });
and php method:
route::post('ajaximage', function(){ $file = request::file('file'); $destinationpath = public_path().'/uploads/'; $filename = $file->getclientoriginalname(); $file->move($destinationpath, $filename); echo url().'/uploads/'.$filename;
});
Comments
Post a Comment