我想用 laravel 5 方法 ajax 覆盖 Summernote 中的图像上传,但我无法让它工作。
这是我的 php 方法
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);
}
});
}
});
我在控制台中收到错误:
发布http://marcus.dev/articles/ajaximage 500(内部服务器错误)
最佳答案
对于 Summernote 0.6.9 版本,我们无法再在回调函数中使用编辑器。
而不是
editor.insertImage(welEditable, url);
我用过
$('#summernote').summernote('editor.insertImage', url);
我不知道是否有更干净的版本,但它似乎可以工作。
关于php - Laravel 5 覆盖summernote 图片上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29866300/