ueditor远程图片本地化的实现
看到了这篇文章,UEditor编辑器如何关闭抓取远程图片本地化功能,so easy?按文章说明设置,测试,失败!
百度看了下,大都是这样解答,说明应该是有人实现了,秀米编辑器核心代码也正是ueditor核心代码,那就只能自己捣鼓了。
具体捣鼓过程如下:
注意:捣鼓前先备份下,以备修改错误导致其他问题
打开ueditor.config.js,在配置项中加入
,catchRemoteImageEnable:true
打开ueditor.config.js,搜索catchremoteimage,在加入console.warn(url),看看上传地址。前台测试后看到/Skin/public/ueditor/php/controller.php?action=catchimage
打开php/controller.php 可以看到
case 'catchimage':
$result = include("action_crawler.php");
break;接着打开统计目录下action_crawler.php
include("Uploader.class.php");
$item = new Uploader($imgUrl, $config, "remote");看到这两段代码。继续打开统计目录下Uploader.class.php
//构造函数如下
public function __construct($fileField, $config, $type = "upload")
{
$this->fileField = $fileField;
$this->config = $config;
$this->type = $type;
if ($type == "remote") {
$this->saveRemote();
} else if($type == "base64") {
$this->upBase64();
} else {
$this->upFile();
}
$this->stateMap['ERROR_TYPE_NOT_ALLOWED'] = iconv('unicode', 'utf-8', $this->stateMap['ERROR_TYPE_NOT_ALLOWED']);
}搜索saveRemote,主要修复fileType与oriName两块。
/**
* 拉取远程图片
* @return mixed
*/
private function saveRemote()
{
$imgUrl = htmlspecialchars($this->fileField);
$imgUrl = str_replace("&", "&", $imgUrl);打开php/config.json,修改大小、格式、存储路径等参数
/ 抓取远程图片配置 / "catcherLocalDomain": ["127.0.0.1", "localhost", "img.baidu.com"], "catcherActionName": "catchimage", / 执行抓取远程图片的action名称 / "catcherFieldName": "source", / 提交的图片列表表单名称 / "catcherPathFormat": "/Upload/ueditor/image/{yyyy}{mm}{dd}/{time}{rand:6}", / 上传保存路径,可以自定义保存路径和文件名格式 / "catcherUrlPrefix": "", / 图片访问路径前缀 / "catcherMaxSize": 20480000, / 上传大小限制,单位B / "catcherAllowFiles": [".png", ".jpg", ".jpeg", ".gif", ".bmp"], / 抓取图片格式显示 /5.保存修改上传,测试成功!










