Php Laravel 5覆盖summernote图像上载
我想用laravel 5方法ajax覆盖summernote中的图像上传,但我无法让它工作 这是我的php方法Php Laravel 5覆盖summernote图像上载,php,jquery,laravel-5,image-upload,summernote,Php,Jquery,Laravel 5,Image Upload,Summernote,我想用laravel 5方法ajax覆盖summernote中的图像上传,但我无法让它工作 这是我的php方法 public function ajaxImage() { $file = Input::file('image'); $destinationPath = public_path(); $filename = $file->getClientOriginalName(); if(Input::file('image')->move($des
public function ajaxImage()
{
$file = Input::file('image');
$destinationPath = public_path();
$filename = $file->getClientOriginalName();
if(Input::file('image')->move($destinationPath, $filename)) {
echo $destinationPath.$filename;
}
}
下面是我的jquery代码:
$(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);
}
});
}
});
我在控制台中得到一个错误:
POST 500(内部服务器错误)我找到了方法。。它是一个 “VerifyCsrfToken中的令牌不匹配异常”问题 资料来源: 我在主视图的标题中添加了以下内容:
<meta name="csrf-token" content="{{ csrf_token() }}" />
最后是php方法:
Route::post('ajaximage',function(){
$file=Request::file('file');
$destinationPath=public_path()。/uploads/;
$filename=$file->getClientOriginalName();
$file->move($destinationPath,$filename);
echo url()。/uploads/。$filename;
});
我找到了。。它是一个
“VerifyCsrfToken中的令牌不匹配异常”问题
资料来源:
我在主视图的标题中添加了以下内容:
<meta name="csrf-token" content="{{ csrf_token() }}" />
最后是php方法:
Route::post('ajaximage',function(){
$file=Request::file('file');
$destinationPath=public_path()。/uploads/;
$filename=$file->getClientOriginalName();
$file->move($destinationPath,$filename);
echo url()。/uploads/。$filename;
});
对于summernote 0.6.9版,我们不能再在回调函数中使用编辑器
而不是
editor.insertImage(welEditable, url);
我曾经
$('#summernote').summernote('editor.insertImage', url);
我不知道是否有更干净的版本,但它似乎可以工作。至于summernote版本0.6.9,我们不能再在回调函数中使用编辑器了 而不是
editor.insertImage(welEditable, url);
我曾经
$('#summernote').summernote('editor.insertImage', url);
我不知道是否有更干净的版本,但它似乎有效。用它找到解决方案。。。。请不要在问题标题中添加已解决的问题。使用该标题查找您的解决方案。。。。请不要在问题标题中添加已解决的问题。对于summernote v0.8.11,正确的代码是:
$(“#summernote”)。summernote('insertImage',url)代码>。还要注意,onImageInsert
现在需要在callbacks
对象中:$('#summernote').summernote({callbacks:{onImageInsert:…}})代码>对于summernote v0.8.11,正确的代码是:$('#summernote')。summernote('insertImage',url)代码>。还要注意,onImageInsert
现在需要在callbacks
对象中:$('#summernote').summernote({callbacks:{onImageInsert:…}})代码>