用ThinkPHP3.2.3搭建一个网站,做个内容管理。用xheditor1.2编辑器,需要上传图片功能。
1.把xheditor编辑器代码包放到public文件夹下。
2.在应用程序的控制器目录下,创建一个UploadController用于上传,里面写个上传方法img_xheditor。
把xheditor包中的upload.php中代码拷贝到这个img_xheditor方法中。设置上传目标文件夹参数$attachDir=‘./Public/upload/xheditor’。注意,一定要有这个'.'表示从这个网站的根目录开始。
3.重要的一步到了,找到以下代码:
$targetPath=jsonString($targetPath);
if($immediate=='1')$targetPath='!'.$targetPath;
if($msgType==1)$msg="'$targetPath'";
在前面加上一行,变成:
//发回的链接要再去掉这个“.”,避免返回链接中多个“.”。
$targetPath = substr($targetPath,1);
$targetPath=jsonString($targetPath);
if($immediate=='1')$targetPath='!'.$targetPath;
if($msgType==1)$msg="'$targetPath'";
4.给需要textarea加js代码变成文本编辑器:
$("textarea.xheditor_uploadimg").xheditor({ upImgUrl: "/Manage/Upload/xheditor_img", upImgExt: "jpg,jpeg,gif,png"});
5.浏览网页,测试上传图片。ok