一前端配置
window.UEDITOR_HOME_URL = "__ROOT__/Public/static/plug/ueditor/";
var ue;
$(function () {
ue = UE.getEditor('container',{
serverUrl:"{:url('Ueditor/action')}",
/*toolbars: [[
'fullscreen', 'source', '|', 'undo', 'redo', '|',
'bold', 'italic', 'underline', 'fontborder', 'strikethrough', 'superscript', 'subscript', 'removeformat', 'formatmatch', 'autotypeset', 'blockquote', 'pasteplain', '|', 'forecolor', 'backcolor', 'insertorderedlist', 'insertunorderedlist', 'selectall', 'cleardoc', '|',
'rowspacingtop', 'rowspacingbottom', 'lineheight', '|',
'customstyle', 'paragraph', 'fontfamily', 'fontsize', '|',
'directionalityltr', 'directionalityrtl', 'indent', '|',
'justifyleft', 'justifycenter', 'justifyright', 'justifyjustify', '|', 'touppercase', 'tolowercase', '|',
'link', 'unlink', 'anchor', '|', 'imagenone', 'imageleft', 'imageright', 'imagecenter', '|','simpleupload', 'emotion', 'scrawl', 'insertvideo', 'music', 'attachment', 'map', 'gmap', 'insertframe', 'insertcode', 'webapp', 'pagebreak', 'template', 'background', '|',
'horizontal', 'date', 'time', 'spechars', 'snapscreen', 'wordimage', '|',
'print', 'preview', 'searchreplace', 'drafts', 'help'
]],*/
toolbars: [
['simpleupload']
],
offsetWidth:800,
initialFrameWidth:800,
initialFrameHeight:800,
imageActionName:"image",
imageFieldName:'image',
imageAllowFiles:[".png", ".jpg", ".jpeg", ".gif", ".bmp"],
imageManagerActionName:"getImageList",
imageManagerUrlPrefix:"",
}).ready(function () {
var that = this;
});
//图片上传
var wul = $(".filePicker");
$.each(wul, function (index, temp) {
wc(temp);
})
})
1ueditor 插件路径 window.UEDITOR_HOME_URL
2serverUrl 服务器地址 serverUrl
3imageActionName 上传图片方法
二获取配置
可以看到百度编辑器加载了这个获取配置的方法,php源码包含错误,则需要修改
$config_path 则为百度编辑器后端配置路径,后端配置图片参数如图,按格式返回后不出现报错了
三图片上传
1可以看到上图,action 方法中调用了$this->image()方法处理上传图片
2腾讯云上传
/**
*上传图片
* @return mixed;
*/
private function image()
{
try {
$file = request()->file('image');
$data = input("post.",null);
$data['image'] = $file;
$flag = $this->validate($data, "Upload.image");
if (true !== $flag) {
return $this->error($flag);
}
$config['upload'] = config("upload");
$image_root= ROOT_PATH.'public'.DS.$config['upload']['tmp'];
if(!file_exists($image_root)){
mkdir($image_root,0777,true);
}
$info = $file->move($image_root);
if ($info) {
// 成功上传后 获取上传信息
$file_path = str_replace('\\', '/', $info->getSaveName());
$image_path = $image_root.$file_path;
$tencent = config('tencent');
$cosClient = new Client(
array(
'region'=>$tencent['region'],
'schema' => 'https', //协议头部,默认为http
'credentials'=> array(
'secretId' => $tencent['secret_id'],
'secretKey' => $tencent['secret_key'],
)
));
$body = fopen($image_path,'rb');
$user = $this->getLoginfo();
$path = $tencent['root']."/".$user['id']."/".$info->getFilename();
$result = $cosClient->Upload($tencent['bucket'],$path,$body);
if(is_resource($body)) {
fclose($body);
};
unlink($image_path);
$res_arr = objectToarray($result);
$url = urldecode($res_arr['Location']);
$data = array(
"state" => 'SUCCESS',
"url" => $url,
"title" => '',
"original" => '',
"type" => '.jpg',
"size" => $info->getInfo('size'),
);
header("Content-type:text/html;charset=utf-8");
echo json_encode($data,JSON_UNESCAPED_SLASHES);
} else {
$data = array(
"state" => 'ERROR_UNKNOWN',
"url" => '',
"title" => '',
"original" => '',
"type" => '.jpg',
"size" => '',
);
header("Content-type:text/html;charset=utf-8");
echo json_encode($data,JSON_UNESCAPED_SLASHES);
}
} catch (Exception $e) {
$data = array(
"state" => 'ERROR_UNKNOWN',
"url" => '',
"title" => '',
"original" => '',
"type" => '.jpg',
"size" => '',
);
header("Content-type:text/html;charset=utf-8");
echo json_encode($data,JSON_UNESCAPED_SLASHES);
}
}
四效果