Thinkphp 3.2.3配置百度编辑器(UEditor)

1、把百度编辑器放到项目的Public目录下 命名为:UEditor

2、找到thinkphp框架系统自带类中的Html.class.php,并且添加在switch(strtoupper($type)) {}中添加代码

case 'UEDITOR':

$parseStr   =  "\n".'<script type="text/javascript" charset="utf-8"

src="__ROOT__/Public/UEditor/ueditor.config.js"></script>'."\n".'

<script type="text/javascript" charset="utf-8"

src="__ROOT__/Public/UEditor/ueditor.all.js"></script>'."\n".'

<script type="text/plain" id="'.$id.'" name="'.$name.'" style="'

.$style.'">'.$content.'</script>'."\n".'<script type="text/javascript">var ue_'.$id.' = UE.getEditor("'.$id.'");</script>'."\n";

break;

3. 在项目文件的www/myproject/Application/Admin/Conf目录下新建ueditconfig.json文件,

4. 把ueditor源码的php文件夹下的config.json中的内容复制到ueditconfig.json文件中

5.在百度编辑器目录的ueditor.config.js文件内修改:(好像可以省略)

// 服务器统一请求接口路径

, serverUrl: URL + "../../index.php/Home/Index/ueditup"

6. 就是你需要的用TP自带上传类处理上传了,在Home模块的Index控制器里加上下面的方法:

public function ueditup(){

header("Content-Type: text/html; charset=utf-8");

$editconfig = json_decode(preg_replace("/\/\*[\s\S]+?\*\//", "", file_get_contents(COMMON_PATH."Conf/ueditconfig.json")), true);

//dump($editconfig);

$action = I('get.action');

//echo $action;

switch ($action) {

case 'config':

$result =  json_encode($editconfig);

break;

/* 上传图片 */

case 'uploadimage':

$result = $this->editup('img');

break;

/* 上传涂鸦 */

case 'uploadscrawl':

$result = $this->editup('img');

break;

case 'uploadvideo':

$result = $this->editup('video');

break;

case 'uploadfile':

$result = $this->editup('file');

//$result = include("action_upload.php");

break;

/* 列出图片 */

case 'listimage':

$result = $this->editlist('listimg');

break;

/* 列出文件 */

case 'listfile':

$result = $this->editlist('listfile');

break;

/* 抓取远程文件 */

case 'catchimage':

//$result = include("action_crawler.php");

break;

default:

$result = json_encode(array(

'state'=> '请求地址出错'

));

break;

}

/* 输出结果 */

if (isset($_GET["callback"])) {

if (preg_match("/^[\w_]+$/", $_GET["callback"])) {

echo htmlspecialchars($_GET["callback"]) . '(' . $result . ')';

} else {

echo json_encode(array(

'state'=> 'callback参数不合法'

));

}

} else {

echo $result;

}

}

public function editup($uptype){

if($this->islogin==false){

$_re_data['state'] = '请登陆';

return json_encode($_re_data);

}

$editconfig = json_decode(preg_replace("/\/\*[\s\S]+?\*\//", "", file_get_contents(COMMON_PATH."Conf/ueditconfig.json")), true);

switch ($uptype) {

case 'img':

$upload = new \Think\Upload();// 实例化上传类

$upload->rootPath  =     '.';

$upload->maxSize   =     $editconfig['imageMaxSize'];

$upload->exts      =     explode('.', trim(join('',$editconfig['imageAllowFiles']),'.'));

$upload->savePath  =     $editconfig['imagePathFormat'];

$upload->saveName  =     time().rand(100000,999999);

$info   =   $upload->uploadOne($_FILES[$editconfig['imageFieldName']]);

break;

case 'file':

$upload = new \Think\Upload();// 实例化上传类

$upload->rootPath  =     '.';

$upload->maxSize   =     $editconfig['fileMaxSize'];

$upload->exts      =     explode('.', trim(join('',$editconfig['fileAllowFiles']),'.'));

$upload->savePath  =     $editconfig['filePathFormat'];

$upload->saveName  =     time().rand(100000,999999);

$info   =   $upload->uploadOne($_FILES[$editconfig['fileFieldName']]);

break;

case 'video':

$upload = new \Think\Upload();// 实例化上传类

$upload->rootPath  =     '.';

$upload->maxSize   =     $editconfig['videoMaxSize'];

$upload->exts      =     explode('.', trim(join('',$editconfig['videoAllowFiles']),'.'));

$upload->savePath  =     $editconfig['videoPathFormat'];

$upload->saveName  =     time().rand(100000,999999);

$info   =   $upload->uploadOne($_FILES[$editconfig['videoFieldName']]);

break;

default:

return false;

break;

}

if(!$info) {// 上传错误提示错误信息

$_re_data['state'] = $upload->getError();

$_re_data['url'] = '';

$_re_data['title'] = '';

$_re_data['original'] = '';

$_re_data['type'] = '';

$_re_data['size'] = '';

}else{// 上传成功 获取上传文件信息

$_re_data['state'] = 'SUCCESS';

$_re_data['url'] = $info['savepath'].$info['savename'];

$_re_data['title'] = $info['savename'];

$_re_data['original'] = $info['name'];

$_re_data['type'] = '.'.$info['ext'];

$_re_data['size'] = $info['size'];

}

return json_encode($_re_data);

}

public function editlist($listtype){

$editconfig = json_decode(preg_replace("/\/\*[\s\S]+?\*\//", "", file_get_contents(COMMON_PATH."Conf/ueditconfig.json")), true);

switch ($listtype) {

case 'listimg':

$allowFiles = $editconfig['imageManagerAllowFiles'];

$listSize = $editconfig['imageManagerListSize'];

$path = $editconfig['imageManagerListPath'];

break;

case 'listfile':

$allowFiles = $editconfig['fileManagerAllowFiles'];

$listSize = $editconfig['fileManagerListSize'];

$path = $editconfig['fileManagerListPath'];

break;

default:

return false;

break;

}

/* 获取参数 */

$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 = $this->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;

}

/**

* 遍历获取目录下的指定类型的文件

* @param $path

* @param array $files

* @return array

*/

public function getfiles($path, $allowFiles, &$files = array())

{

if (!is_dir($path)) return null;

if(substr($path, strlen($path) - 1) != '/') $path .= '/';

$handle = opendir($path);

while (false !== ($file = readdir($handle))) {

if ($file != '.' && $file != '..') {

$path2 = $path . $file;

if (is_dir($path2)) {

$this->getfiles($path2, $allowFiles, $files);

} else {

if(in_array('.'.pathinfo($file, PATHINFO_EXTENSION), $allowFiles)){

$files[] = array(

'url'=> substr($path2, strlen($_SERVER['DOCUMENT_ROOT'])),

'mtime'=> filemtime($path2)

);

}

}

}

}

return $files;

}

(7.8在一个页面进行)

7. 在需要用到编辑器的模板head内加上: (哪里需要它就就调用)

<taglib name="html" />

8. 在用到编辑器的地方加上:(哪里需要它就就调用)

<html:editor id="info" name="info" type="UEDITOR" >{$info.info}</html:editor>

综上效果

补充:使用UEDITOR存在数据库的资料带有标签和样式

当我们打印值的时候会出现如下情况(需要)

<{:htmlspecialchars_decode($xx['xx'])}>

Thinkphp 3.2.3配置百度编辑器(UEditor)的更多相关文章

  1. 关于百度编辑器UEditor的一点说明

    大家在使用的时候要特别注意editor_config.js中的“URL”这个参数 我的理解:1.这个参数是editor整个结构的总路径          2.首先要把这个路径配置好了.才能正常的显示, ...

  2. [转载]百度编辑器-Ueditor使用

    前段时间发表过一篇关于“KindEditor在JSP中使用”的博文.这几天在沈阳东软进行JavaWeb方面的实习工作,在一个CMS系统的后台和博客板块中又要用到文本编辑器,突然发现了这个——百度编辑器 ...

  3. 百度编辑器 ueditor .net开发

    ueditor1.4.3 下载地址:http://pan.baidu.com/s/1bnCQVtd   <!--editor--> <script type="text/j ...

  4. drupal7 安装百度编辑器Ueditor及后续使用

    参考文章:drupal7安装百度编辑器ueditor 一.下载 1.需要下载安装的模块: 1.1.wysiwyg 1.2.ueditor 1.3Libraries 下载后安装在\sites\all\m ...

  5. 解决:百度编辑器UEditor,怎么将图片保存到图片服务器,或者上传到ftp服务器的问题(如果你正在用UE,这篇文章值得你看下)

    在使用百度编辑器ueditor的时候,怎么将图片保存到另一个服务器,或者上传到ftp服务器?这个问题,估计很多使用UE的人会遇到.而且我百度过,没有找到这个问题的解决方案.那么:本篇文章就很适合你了. ...

  6. 百度编辑器UEditor,保存图片的配置问题

    前言: 在使用百度编辑器UEditor的时候,如何将图片保存到服务器,我刚开始以为是要自己写上传文件的方法,后来发现只需要配置一下即可,如果你也正在使用百度富文本编辑器UEditor的话,这篇文章将非 ...

  7. 百度编辑器ueditor插入表格没有边框颜色的解决方法

    附:从word excel 中 复制的表格提交后无边框,参考这个同学的,写的很详细:   http://blog.csdn.net/lovelyelfpop/article/details/51678 ...

  8. 百度编辑器ueditor插入表格没有边框,没有颜色的解决方法 2015-01-06 09:24 98人阅读 评论(0) 收藏

    百度富文本编辑器..很强大.. - - ,不过有些BUG..真的很无解.. 最近用这个,发现上传的表格全部没有表框.. 解决办法如下: 转载的.. 百度编辑器ueditor插入一个表格后,在编辑过程中 ...

  9. 百度编辑器ueditor 异步加载时,初始化没办法赋值bug解决方法

    百度编辑器ueditor 异步加载时,初始化没办法赋值bug解决方法 金刚 前端 ueditor 初始化 因项目中使用了百度编辑器——ueditor.整体来说性能还不错. 发现问题 我在做一个编辑页面 ...

随机推荐

  1. Ubuntu/Debian下通过Apt-get简单安装Oracle JDK

    近几年本人对各种Arm小板,开发板不明原因中毒,基本以Linux系统为主,本篇文章以记录在32位Arm的Debian8上,通过Apt-get的简单命令安装Oracle JDK8并成功的记录. 1.首先 ...

  2. Thread in depth 3:Synchronization

    Synchronization means multi threads access the same resource (data, variable ,etc) should not cause ...

  3. 我要总结基本书 .net稍微有些深度的书籍看看

    1. 你必须知道的.NET 2. C# in depth 3.C#并发编程经典实例 4.ASP.NET MVC 4框架揭秘 5.NET最佳实践 6..NET探秘 .NET安全编程 .NET企业服务框架 ...

  4. [MySQL Tips]:如何删除unique key约束

    [场景]: 假设最初创建了一个表bank,在street属性上添加了unique约束. create table branch( branch_name ) not null primary key, ...

  5. ASP.NET MVC 中单独的JS文件中获取Controller中设定的值

    1,在Controller中的Action 中将指定值写上.       //       // GET: /Home/       public ActionResult Index()       ...

  6. azkaban作业参数使用介绍

    azkaban作业参数使用介绍 参数传递是调度系统工作流运行时非常重要的一部分,工作流的执行,单个作业的执行,多个工作流之间的依赖执行,历史任务重算,都涉及参数传递和同步. azkaban的工作流中的 ...

  7. C# 图片反色处理 图片夜间模式

    项目属性-->生成-->允许不安全代码勾上. 代码: /// <summary> /// 反色处理 /// </summary> private Bitmap In ...

  8. spring jdbc批量插入

    http://blog.csdn.net/fyqcdbdx/article/details/7366439

  9. 20164317《网络对抗技术》Exp4 恶意代码分析

    1.实践目标 1.是监控你自己系统的运行状态,看有没有可疑的程序在运行. 2.是分析一个恶意软件,就分析Exp2或Exp3中生成后门软件:分析工具尽量使用原生指令或sysinternals,systr ...

  10. Android代码编译出现的错误

    一.decoupled apps failed  解耦应用程序失败 2.每次编译时候一定先扩充内存 export JACK_SERVER_VM_ARGUMENTS="-Dfile.encod ...