新版本的ueditor编辑器内为了安全考虑不在自带后台程序编码,所以导致我们下载下来得ueditor使用中报错 “请求后台配置项http错误,上传功能将不能正常使用!”
解决办法
打开ueditor本目录下的ueditor.confin.js将serverUrl修改为您的上传接口(大约在31行左右)
serverUrl: "/admin/index/upload",
此方法是后台上传接口
public function upload(){
$action = $this->request->param('action');
switch($action){
case 'config':
$result = file_get_contents(ROOT_PATH.'public/static/js/ueditor/config.json');
break;
case 'uploadimage':
$file = $this->request->file('upfile');
if($file){
$info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
$res = $info->getInfo();
$res['state'] = 'SUCCESS';
$res['url'] = $info->getSaveName();
$result = json_encode($res);
}
break;
default:
break;
}
return $result;
}
在ueditor的跟目录新建一个config.json将下面内容复制进入后即可
/* 上传图片配置项 */
"imageActionName": "uploadimage", /* 执行上传图片的action名称 */
"imageFieldName": "upfile", /* 提交的图片表单名称 */
"imageMaxSize": 2048000, /* 上传大小限制,单位B */
"imageAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"], /* 上传图片格式显示 */
"imageCompressEnable": true, /* 是否压缩图片,默认是true */
"imageCompressBorder": 1600, /* 图片压缩最长边限制 */
"imageInsertAlign": "none", /* 插入的图片浮动方式 */
"imageUrlPrefix": "http://localhost/bbs/public/uploads/", /* 图片访问路径前缀 */
"imagePathFormat": "/upload/{yyyy}{mm}{dd}/{time}{rand:6}", /* 上传保存路径,可以自定义保存路径和文件名格式 */
再次刷新编辑器页面即可正常使用