thinphp 整合ueditor
我的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'));
thinphp 整合ueditor的更多相关文章
- thinkphp 3.2.3整合ueditor 1.4,给上传的图片加水印
今天分享一下thinkphp 3.2.3整合ueditor 1.4,给上传的图片加水印.博主是新手,在这里卡住了很久(>_<) thinkphp 3.2.3整合ueditor 1.4 下载 ...
- Dedecmsv5.7整合ueditor 图片上传添加水印
最近的项目是做dedecmsv5.7的二次开发,被要求上传的图片要加水印,百度ueditor编辑器不支持自动加水印,所以,找了很多资料整合记录一下,具体效果图 这里不仔细写dedecmsv5.7 整合 ...
- 很详细的SpringBoot整合UEditor教程
很详细的SpringBoot整合UEditor教程 2017年04月10日 20:27:21 小宝2333 阅读数:21529 版权声明:本文为博主原创文章,未经博主允许不得转载. https: ...
- CI框架整合UEditor编辑器上传功能
最近项目中要使用到富文本编辑器,选用了功能强大的UEditor,接下来就来讲讲UEditor编辑器的上传功能整合. 本文UEditor版本:ueditor1_4_3_utf8_php版本 第一步:部署 ...
- springboot整合ueditor实现图片上传和文件上传功能
springboot整合ueditor实现图片上传和文件上传功能 写在前面: 在阅读本篇之前,请先按照我的这篇随笔完成对ueditor的前期配置工作: springboot+layui 整合百度富文本 ...
- activiti自定义流程之整合(二):使用angular js整合ueditor创建表单
注:整体环境搭建:activiti自定义流程之整合(一):整体环境配置 基础环境搭建完毕,接下来就该正式着手代码编写了,在说代码之前,我觉得有必要先说明一下activit自定义流程的操作. 抛开自定义 ...
- springMVC -- 整合UEditor(富文本编辑器)
工作中需要用到UEditor编辑文本,在与springMVC进行整合时,出现了一些问题,结果导致,在进行图片上传时出现如下提示: 上网查询了很多相关资料,此处简要记录下,防止以后遇到类似问题. 一种方 ...
- 七牛整合 ueditor (拦住那头牛,七牛又如何)
最近遇到个项目,要求所有图片都必须整合到七牛上,看了把你谈文档踩在前辈们的基础上终于把他完成了,恰巧本屌丝最近刚好有时间,本着天下屌丝是一家的原则,和小朋友们一同学习 闲话少说入正题. 第一 :下载编 ...
- JAVA SpringBoot2 整合 JSP视图模板 整合 Ueditor富文本编辑器
一般涉及到后台管理系统,就少不了富文本编辑器,这个可以图,文,视频混排的高级工具,笔者通过对比,发现目前市场上最好的三方库还当属百度的 ueditor 近年来 SpringBoot 框架可谓越来越火, ...
随机推荐
- dom4j读取xml
-----记录和回顾是一个比学习更重要的环节----- 一.首先,我们需要知道xml是做什么的 1.作为软件的配置文件 2.作为数据的载体(小型的数据库) 二.xml的语法 xml文件以xml后缀名结 ...
- Windows系统安装pip方法
pip是一款非常方便的python包管理工具,本文主要介绍在windows 10系统下安装pip方法. 1. 下载pip 地址:https://pypi.python.org/pypi/pip#dow ...
- java重定向
package com.sn.servlet; import java.io.IOException; import javax.servlet.ServletException; import ja ...
- CCF NOI plus 201(7)6 初赛题 解题报告
GTMDCCF. 今年这题怎么评价? 去看我在知乎的回答:https://www.zhihu.com/question/66621360/answer/244222388 挨个说一遍. 单项选择题 T ...
- BZOJ 3265: 志愿者招募加强版 [单纯形法]
传送门 一个人多段区间,一样.... 不过国家队论文上说这道题好像不能保证整数解.... #include <iostream> #include <cstdio> #incl ...
- HTTP面试题都在这里
HTTP常见面试题 Http与Https的区别: Http与Https的区别: HTTP 的URL 以http:// 开头,而HTTPS 的URL 以https:// 开头 HTTP 是不安全的,而 ...
- 新版Azure Automation Account 浅析(三) --- 用Runbook管理AAD Application Key
新版Azure Automation Account 浅析(三) --- 用Runbook管理AAD应用的Key 前篇讲过有一个面向公众的Runbook库,社区和微软一直往其中加入新的Runbook, ...
- stderr,stdout,a.txt缓冲区别
#include<stdlib.h>#include<stdio.h>#include<string.h>#include<error.h>#inclu ...
- a元素的两个重要功能和表格布局
⦁ 发送邮件:<a href="mailto:231455557@qq.com">联系我们</a> ⦁ 锚点两个重要应用:查看目录 提供菜单功能回到顶 ...
- PHP curl 常用操作
网页内容替换 $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, "http://www.baidu.com"); //执行后 ...