我的ueditor是部署在public/editor
部署前台页面
<script type="text/javascript" >
var UEDITOR_HOME_URL: "__PUBLIC__/ueditor/"
</script> <script id="container" name="$des" type="text/plain">
这里写你的初始化内容
</script> <!-- 配置文件 -->
<script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.config.js"></script>
<!-- 编辑器源码文件 -->
<script type="text/javascript" src="__PUBLIC__/ueditor/ueditor.all.js"></script>
<!-- 实例化编辑器 -->
<script type="text/javascript">
var ue = UE.getEditor('container',{
autoHeight: false,
});
</script>
修改上传配置信息
ueditor所有上传文件的配置都在config.json文件中。
上传路径修改成自己需要的
更改服务器统一入口文件
修改ueditor.config.js文件
统一入口都走public模块的editor 方法。
// 服务器统一请求接口路径
, serverUrl: "http://localhost/index.php?m=Public&a=editor"
开发一个public 公共的模块
代码我就直接用的ueditor提供的demo。
public function getConf(){
$CONFIG = json_decode(preg_replace("/\/\*[\s\S]+?\*\//", "", file_get_contents("public/ueditor/config.json")), true);
return $CONFIG;
}
public function verify(){
import('ORG.Util.Image');
Image::buildImageVerify();
}
public function upload(){
import('ORG.Net.UploadFile');
$upload = new UploadFile();// 实例化上传类
$upload->maxSize = 1024*1024 ;// 设置附件上传大小
$upload->thumb=true;
$upload->thumbMaxWidth='150,100';
$upload->thumbMaxHeight='150,50';
$upload->thumbPrefix="mid_,small_";
$upload->autoSub=true;
$upload->subType=date;
$upload->dateFormat='Ymd';
$upload->allowExts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
$upload->savePath = './Public/Uploads/';// 设置附件上传目录
if(!$upload->upload()) {// 上传错误提示错误信息
$this->error($upload->getErrorMsg());
}else{// 上传成功 获取上传文件信息
$info = $upload->getUploadFileInfo();
return $info;
}
} public function action_list(){
$CONFIG=$this->getConf();
/* 判断类型 */
switch ($_GET['action']) {
/* 列出文件 */
case 'listfile':
$allowFiles = $CONFIG['fileManagerAllowFiles'];
$listSize = $CONFIG['fileManagerListSize'];
$path = $CONFIG['fileManagerListPath'];
break;
/* 列出图片 */
case 'listimage':
default:
$allowFiles = $CONFIG['imageManagerAllowFiles'];
$listSize = $CONFIG['imageManagerListSize'];
$path = $CONFIG['imageManagerListPath'];
}
$allowFiles = substr(str_replace(".", "|", join("", $allowFiles)), 1); /* 获取参数 */
$size = isset($_GET['size']) ? htmlspecialchars($_GET['size']) : $listSize;
$start = isset($_GET['start']) ? htmlspecialchars($_GET['start']) : 0;
$end = $start + $size; /* 获取文件列表 */
$path = $_SERVER['DOCUMENT_ROOT'] . (substr($path, 0, 1) == "/" ? "":"/") . $path;
$files = getfiles($path, $allowFiles);
if (!count($files)) {
return json_encode(array(
"state" => "no match file",
"list" => array(),
"start" => $start,
"total" => count($files)
));
} /* 获取指定范围的列表 */
$len = count($files);
for ($i = min($end, $len) - 1, $list = array(); $i < $len && $i >= 0 && $i >= $start; $i--){
$list[] = $files[$i];
}
//倒序
//for ($i = $end, $list = array(); $i < $len && $i < $end; $i++){
// $list[] = $files[$i];
//} /* 返回数据 */
$result = json_encode(array(
"state" => "SUCCESS",
"list" => $list,
"start" => $start,
"total" => count($files)
)); return $result; }
public function action_upload(){
import('ORG.Net.Uploader');
$CONFIG=$this->getConf();
/* 上传配置 */
$base64 = "upload";
switch (htmlspecialchars($_GET['action'])) {
case 'uploadimage':
$config = array(
"pathFormat" => $CONFIG['imagePathFormat'],
"maxSize" => $CONFIG['imageMaxSize'],
"allowFiles" => $CONFIG['imageAllowFiles']
);
$fieldName = $CONFIG['imageFieldName'];
break;
case 'uploadscrawl':
$config = array(
"pathFormat" => $CONFIG['scrawlPathFormat'],
"maxSize" => $CONFIG['scrawlMaxSize'],
"allowFiles" => $CONFIG['scrawlAllowFiles'],
"oriName" => "scrawl.png"
);
$fieldName = $CONFIG['scrawlFieldName'];
$base64 = "base64";
break;
case 'uploadvideo':
$config = array(
"pathFormat" => $CONFIG['videoPathFormat'],
"maxSize" => $CONFIG['videoMaxSize'],
"allowFiles" => $CONFIG['videoAllowFiles']
);
$fieldName = $CONFIG['videoFieldName'];
break;
case 'uploadfile':
default:
$config = array(
"pathFormat" => $CONFIG['filePathFormat'],
"maxSize" => $CONFIG['fileMaxSize'],
"allowFiles" => $CONFIG['fileAllowFiles']
);
$fieldName = $CONFIG['fileFieldName'];
break;
} /* 生成上传实例对象并完成上传 */
$up = new Uploader($fieldName, $config, $base64); /**
* 得到上传文件所对应的各个参数,数组结构
* array(
* "state" => "", //上传状态,上传成功时必须返回"SUCCESS"
* "url" => "", //返回的地址
* "title" => "", //新文件名
* "original" => "", //原始文件名
* "type" => "" //文件类型
* "size" => "", //文件大小
* )
*/ /* 返回数据 */
return json_encode($up->getFileInfo()); }
/**
* 编辑器
*/
public function editor(){
$CONFIG = $this->getConf();
$action = $_GET['action']; switch ($action) {
case 'config':
$result = json_encode($CONFIG);
break; /* 上传图片 */
case 'uploadimage':
/* 上传涂鸦 */
case 'uploadscrawl':
/* 上传视频 */
case 'uploadvideo':
/* 上传文件 */
case 'uploadfile':
$result = $this->action_upload();
break; /* 列出图片 */
case 'listimage':
$result =$this-> action_list();
break;
/* 列出文件 */
case 'listfile':
$result = $this-> action_list();
break; /* 抓取远程文件 */
case 'catchimage':
$result = $this-> action_crawler();
break; default:
$result = json_encode(array(
'state'=> '请求地址出错'
));
break;
} /* 输出结果 */
if (isset($_GET["callback"])) {
if (preg_match("/^[\w_]+$/", $_GET["callback"])) {
//echo htmlspecialchars($_GET["callback"]) . '(' . $result . ')';
//echo ($_GET["callback"]) . '(' . $result . ')';
die(($_GET["callback"]) . '(' . $result . ')');
} else {
echo json_encode(array(
'state'=> 'callback参数不合法'
));
}
} else {
echo $result;
}
}
/**
* 上传抓图
*/
public function action_crawler(){
import('ORG.Net.Uploader');
$CONFIG=$this->getConf();
/* 上传配置 */
$config = array(
"pathFormat" => $CONFIG['catcherPathFormat'],
"maxSize" => $CONFIG['catcherMaxSize'],
"allowFiles" => $CONFIG['catcherAllowFiles'],
"oriName" => "remote.png"
);
$fieldName = $CONFIG['catcherFieldName']; /* 抓取远程图片 */
$list = array();
if (isset($_POST[$fieldName])) {
$source = $_POST[$fieldName];
} else {
$source = $_GET[$fieldName];
}
foreach ($source as $imgUrl) {
$item = new Uploader($imgUrl, $config, "remote");
$info = $item->getFileInfo();
array_push($list, array(
"state" => $info["state"],
"url" => $info["url"],
"size" => $info["size"],
"title" => htmlspecialchars($info["title"]),
"original" => htmlspecialchars($info["original"]),
"source" => htmlspecialchars($imgUrl)
));
} /* 返回抓取数据 */
return json_encode(array(
'state'=> count($list) ? 'SUCCESS':'ERROR',
'list'=> $list
));
}
控制器接收数据
要使用htmlspecialchars_decode把一些预定义的 HTML 实体转换为字符
$data['des']=htmlspecialchars_decode($this->_post('des'));