上传图片不成功,新版的富文本报错

来源:4-13 csrf+富文本编辑器创建文章(下)

慕运维9439573

2017-12-15

public function imageUpload(Request $request){
    $path=$request->file('2_jpg')->storePublicly(md5(time()));
    $data=asset('storage/'.$path);
    echo json_encode(array("errno"=>0,"data"=>$data));
    
    var E = window.wangEditor
var editor = new E('#div1')
var $text1 = $('#content')
editor.customConfig.onchange = function (html) {
    // 监控变化,同步更新到 textarea
    $text1.val(html)
}
// 下面两个配置,使用其中一个即可显示“上传图片”的tab。但是两者不要同时使用!!!
//editor.customConfig.uploadImgShowBase64 = true   // 使用 base64 保存图片
//editor.customConfig.uploadImgServer = '/upload'  // 上传图片到服务器
editor.customConfig.uploadImgServer = '/posts/image/upload';
editor.customConfig.uploadFileName = 'yxs'
//设置headers(举例)
editor.customConfig.uploadImgHeaders = {
    'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
editor.create()
// 初始化 textarea 的值
$text1.val(editor.txt.html())

http://img.mukewang.com/szimg/5a33adc700013e9008080244.jpg

写回答

1回答

轩脉刃

2017-12-17

提示你$request->file('2_jpg') 这个获取是null,可以这样排查:先用chrome的控制台,找到上传的post请求,查看body里面上传的文件名


//img.mukewang.com/szimg/5a35ec2400012f4121980774.jpg

0
0

Laravel快速开发简书

Laravel最新特性结合Mysql异步消息队列、ElasticSearch搜索引擎、Debugbar调试利器开发简书

1218 学习 · 613 问题

查看课程