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 方法。
1 // 服务器统一请求接口路径 2 , serverUrl: "http://localhost/index.php?m=Public&a=editor"
开发一个public 公共的模块
代码我就直接用的ueditor提供的demo。
1 public function getConf(){ 2 $CONFIG = json_decode(preg_replace("/\/\*[\s\S]+?\*\//", "", file_get_contents("public/ueditor/config.json")), true); 3 return $CONFIG; 4 } 5 public function verify(){ 6 import('ORG.Util.Image'); 7 Image::buildImageVerify(); 8 } 9 public function upload(){ 10 import('ORG.Net.UploadFile'); 11 $upload = new UploadFile();// 实例化上传类 12 $upload->maxSize = 1024*1024 ;// 设置附件上传大小 13 $upload->thumb=true; 14 $upload->thumbMaxWidth='150,100'; 15 $upload->thumbMaxHeight='150,50'; 16 $upload->thumbPrefix="mid_,small_"; 17 $upload->autoSub=true; 18 $upload->subType=date; 19 $upload->dateFormat='Ymd'; 20 $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型 21 $upload->savePath = './Public/Uploads/';// 设置附件上传目录 22 if(!$upload->upload()) {// 上传错误提示错误信息 23 $this->error($upload->getErrorMsg()); 24 }else{// 上传成功 获取上传文件信息 25 $info = $upload->getUploadFileInfo(); 26 return $info; 27 } 28 } 29 30 public function action_list(){ 31 $CONFIG=$this->getConf(); 32 /* 判断类型 */ 33 switch ($_GET['action']) { 34 /* 列出文件 */ 35 case 'listfile': 36 $allowFiles = $CONFIG['fileManagerAllowFiles']; 37 $listSize = $CONFIG['fileManagerListSize']; 38 $path = $CONFIG['fileManagerListPath']; 39 break; 40 /* 列出图片 */ 41 case 'listimage': 42 default: 43 $allowFiles = $CONFIG['imageManagerAllowFiles']; 44 $listSize = $CONFIG['imageManagerListSize']; 45 $path = $CONFIG['imageManagerListPath']; 46 } 47 $allowFiles = substr(str_replace(".", "|", join("", $allowFiles)), 1); 48 49 /* 获取参数 */ 50 $size = isset($_GET['size']) ? htmlspecialchars($_GET['size']) : $listSize; 51 $start = isset($_GET['start']) ? htmlspecialchars($_GET['start']) : 0; 52 $end = $start + $size; 53 54 /* 获取文件列表 */ 55 $path = $_SERVER['DOCUMENT_ROOT'] . (substr($path, 0, 1) == "/" ? "":"/") . $path; 56 $files = getfiles($path, $allowFiles); 57 if (!count($files)) { 58 return json_encode(array( 59 "state" => "no match file", 60 "list" => array(), 61 "start" => $start, 62 "total" => count($files) 63 )); 64 } 65 66 /* 获取指定范围的列表 */ 67 $len = count($files); 68 for ($i = min($end, $len) - 1, $list = array(); $i < $len && $i >= 0 && $i >= $start; $i--){ 69 $list[] = $files[$i]; 70 } 71 //倒序 72 //for ($i = $end, $list = array(); $i < $len && $i < $end; $i++){ 73 // $list[] = $files[$i]; 74 //} 75 76 /* 返回数据 */ 77 $result = json_encode(array( 78 "state" => "SUCCESS", 79 "list" => $list, 80 "start" => $start, 81 "total" => count($files) 82 )); 83 84 return $result; 85 86 } 87 public function action_upload(){ 88 import('ORG.Net.Uploader'); 89 $CONFIG=$this->getConf(); 90 /* 上传配置 */ 91 $base64 = "upload"; 92 switch (htmlspecialchars($_GET['action'])) { 93 case 'uploadimage': 94 $config = array( 95 "pathFormat" => $CONFIG['imagePathFormat'], 96 "maxSize" => $CONFIG['imageMaxSize'], 97 "allowFiles" => $CONFIG['imageAllowFiles'] 98 ); 99 $fieldName = $CONFIG['imageFieldName']; 100 break; 101 case 'uploadscrawl': 102 $config = array( 103 "pathFormat" => $CONFIG['scrawlPathFormat'], 104 "maxSize" => $CONFIG['scrawlMaxSize'], 105 "allowFiles" => $CONFIG['scrawlAllowFiles'], 106 "oriName" => "scrawl.png" 107 ); 108 $fieldName = $CONFIG['scrawlFieldName']; 109 $base64 = "base64"; 110 break; 111 case 'uploadvideo': 112 $config = array( 113 "pathFormat" => $CONFIG['videoPathFormat'], 114 "maxSize" => $CONFIG['videoMaxSize'], 115 "allowFiles" => $CONFIG['videoAllowFiles'] 116 ); 117 $fieldName = $CONFIG['videoFieldName']; 118 break; 119 case 'uploadfile': 120 default: 121 $config = array( 122 "pathFormat" => $CONFIG['filePathFormat'], 123 "maxSize" => $CONFIG['fileMaxSize'], 124 "allowFiles" => $CONFIG['fileAllowFiles'] 125 ); 126 $fieldName = $CONFIG['fileFieldName']; 127 break; 128 } 129 130 /* 生成上传实例对象并完成上传 */ 131 $up = new Uploader($fieldName, $config, $base64); 132 133 /** 134 * 得到上传文件所对应的各个参数,数组结构 135 * array( 136 * "state" => "", //上传状态,上传成功时必须返回"SUCCESS" 137 * "url" => "", //返回的地址 138 * "title" => "", //新文件名 139 * "original" => "", //原始文件名 140 * "type" => "" //文件类型 141 * "size" => "", //文件大小 142 * ) 143 */ 144 145 /* 返回数据 */ 146 return json_encode($up->getFileInfo()); 147 148 } 149 /** 150 * 编辑器 151 */ 152 public function editor(){ 153 $CONFIG = $this->getConf(); 154 $action = $_GET['action']; 155 156 switch ($action) { 157 case 'config': 158 $result = json_encode($CONFIG); 159 break; 160 161 /* 上传图片 */ 162 case 'uploadimage': 163 /* 上传涂鸦 */ 164 case 'uploadscrawl': 165 /* 上传视频 */ 166 case 'uploadvideo': 167 /* 上传文件 */ 168 case 'uploadfile': 169 $result = $this->action_upload(); 170 break; 171 172 /* 列出图片 */ 173 case 'listimage': 174 $result =$this-> action_list(); 175 break; 176 /* 列出文件 */ 177 case 'listfile': 178 $result = $this-> action_list(); 179 break; 180 181 /* 抓取远程文件 */ 182 case 'catchimage': 183 $result = $this-> action_crawler(); 184 break; 185 186 default: 187 $result = json_encode(array( 188 'state'=> '请求地址出错' 189 )); 190 break; 191 } 192 193 /* 输出结果 */ 194 if (isset($_GET["callback"])) { 195 if (preg_match("/^[\w_]+$/", $_GET["callback"])) { 196 //echo htmlspecialchars($_GET["callback"]) . '(' . $result . ')'; 197 //echo ($_GET["callback"]) . '(' . $result . ')'; 198 die(($_GET["callback"]) . '(' . $result . ')'); 199 } else { 200 echo json_encode(array( 201 'state'=> 'callback参数不合法' 202 )); 203 } 204 } else { 205 echo $result; 206 } 207 } 208 /** 209 * 上传抓图 210 */ 211 public function action_crawler(){ 212 import('ORG.Net.Uploader'); 213 $CONFIG=$this->getConf(); 214 /* 上传配置 */ 215 $config = array( 216 "pathFormat" => $CONFIG['catcherPathFormat'], 217 "maxSize" => $CONFIG['catcherMaxSize'], 218 "allowFiles" => $CONFIG['catcherAllowFiles'], 219 "oriName" => "remote.png" 220 ); 221 $fieldName = $CONFIG['catcherFieldName']; 222 223 /* 抓取远程图片 */ 224 $list = array(); 225 if (isset($_POST[$fieldName])) { 226 $source = $_POST[$fieldName]; 227 } else { 228 $source = $_GET[$fieldName]; 229 } 230 foreach ($source as $imgUrl) { 231 $item = new Uploader($imgUrl, $config, "remote"); 232 $info = $item->getFileInfo(); 233 array_push($list, array( 234 "state" => $info["state"], 235 "url" => $info["url"], 236 "size" => $info["size"], 237 "title" => htmlspecialchars($info["title"]), 238 "original" => htmlspecialchars($info["original"]), 239 "source" => htmlspecialchars($imgUrl) 240 )); 241 } 242 243 /* 返回抓取数据 */ 244 return json_encode(array( 245 'state'=> count($list) ? 'SUCCESS':'ERROR', 246 'list'=> $list 247 )); 248 }
控制器接收数据
要使用htmlspecialchars_decode把一些预定义的 HTML 实体转换为字符
1 $data['des']=htmlspecialchars_decode($this->_post('des'));
转载于:https://www.cnblogs.com/tl542475736/p/3903646.html
thinphp 整合ueditor相关推荐
- editor.md七牛云上传图片springboot_spring boot 若依系统整合Ueditor,部署时候上传图片错误解决...
spring boot 若依系统整合Ueditor,部署时候上传图片错误解决 前言:国庆假期找了个ruoyi版本的cms玩玩,从git上看,介绍如下图: 后台部分截图: 编辑 编辑 编辑 ...
- 很详细的SpringBoot整合UEditor教程
很详细的SpringBoot整合UEditor教程 2017年04月10日 20:27:21 小宝2333 阅读数:21529 版权声明:本文为博主原创文章,未经博主允许不得转载. https://b ...
- vue项目整合UEditor看这一篇就够了
前言 vue整合UEditor的需求,在整合过程中遇到不少问题,关于这方面在网上的资料也不少,但是没有一个能解决问题,在开发的过程中,几乎所有的问题能出现的都遇到了,比如图片上传提示没有后端服务配置, ...
- phpcms v9整合Ueditor
所有写文章的乐趣会被一个蹩脚的ckeditor打消,PC论坛多次呼声官方替换默认的编辑器为UEditor,但是至今没下文,百度一大堆整合1.2几版的,基于程序员的用新版的强迫症,还是觉得自己搞一搞. ...
- SpringBoot2.x 整合 Ueditor
文章目录 一.基础准备 1. 创建项目并引入依赖 2. 下载Ueditor源码 3. Java代码整合 4. 静态文件整合 二.静态页面+控制层 2.1. index.html 2.2. demo1. ...
- 整合UEditor,SSH下
一.整合所需UEditor原代码 这个可以到http://ueditor.baidu.com/website/download.html#ueditor下载相应版本. 二.导包 把上述包拷贝到WEB- ...
- 6kzz整合ueditor
用过6kzz免费版的朋友都知道,它的后台编辑器是kindeditor,并且是两三年前的版本,有很多功能都没有,现在的kindeditor也不错,但感觉还是没有百度的ueditor强大(据说微信后台的编 ...
- ueditor上传图片回调_springboot+mybatis+oss整合ueditor
今天项目的管理后台需要用到编辑器,之前有用到一款编辑器,叫做wangEditor,这款编辑器虽然接入是很快,给我的感觉就是傻白甜,但是他的编辑器的功能是比较少,后面又将编辑器改成了百度的ueditor ...
- thinkphp整合Ueditor编辑器
编辑器下载地址:http://ueditor.baidu.com/website/download.html#ueditor 放在项目Public或者入口同级目录均可. 前台代码 <div cl ...
最新文章
- amaze ui各个模块简单说明
- beta冲刺(2/7)
- 自动化测试框架的一些建议
- java system.setproperties_在JAVA中 System.getProperty 和 System.setProperty 方法.
- 18秋学期《计算机网络》在线作业,18秋北交《计算机应用基础及计算机网络与应用》在线作业一-2辅导资料.docx...
- React实现图片自适应
- 倍福 在 vs 里 编程 是怎么做到的_截图里的文字要改,字体怎么做到一模一样?...
- VS开发中的代码编写小技巧——避免重复代码编写的几种方法
- 普通的测试员和牛逼的测试员有什么区别?完成这两次跨越,你也可以
- 思科 计算机网络 期末考试答案
- c 登录窗口 oracle,C语言实现图形界面登陆窗口
- Java 微信对账单
- 联想笔记本电脑安装Ubuntu18.04系统
- MT7682参考手册,MT7682芯片资料介绍
- ​汽车域控制器架构和OTA的心脏:网关的四大豪门(下)
- MFC、WTL、WPF、wxWidgets、Qt、GTK 对比
- 一文深刻解析UWB是什么技术?
- #Reading Paper# 【序列推荐】ICKM 2022 RETR:Recommender Transformers with Behavior Pathways
- Linux下安装安装redis
- dotnet 读 WPF 源代码笔记 WriteableBitmap 的渲染和更新是如何实现
热门文章
- java工具集_Java 工具集
- mysql reflush pri_mysql忘记root密码拯救方法(flush privileges)
- 平年闰年c语言源代码,C语言平年闰年问题
- 【C++】多态(早期绑定、后期绑定)、抽象类(纯虚函数)、虚析构函数
- html表格中加入斜线,在HTML中显示带斜线的表格
- 使用Python,dlib,OpenCV在实时的视频流中进行面部标志检测
- Open3d学习计划—高级篇 3(点云全局配准)
- OpenGL如何处理多个纹理
- OpenResty学习中的几个小例子汇总
- 在CentOS 6.6 64bit上编译安装LLVM3.7,Clang,Libc++和libc++abi