彰化一整天的論壇

 找回密碼
 立即註冊
搜索
查看: 18|回復: 0

[轉貼】CKEditor 添加图片上传功能

[複製鏈接]
發表於 2018-1-4 17:14:01 | 顯示全部樓層 |閱讀模式
CKEditor默认没有图片上传功能,官网默认是配合CKFinder使用的套路,但是有的时候就是懒得配置,所以就有这么一篇了,

其实很简单 4 步

1,检查你的编辑器有图片按钮
2,开启图片的上传对话框:在ckeditor\plugins\image\dialogs\image.js 里查找  filebrowserImageBrowseLinkUrl , 把它后面的有个hidden的值改为false,
同理,后面还有一个Upload 也把它的hidden改为false
(这里使用的是CKEditor 4.5.9版本)

3,对CKEditor设置图片上传的接收url,就是告诉编辑器上传图片是发送到哪个url
在CKEditor.config 中设置 config.filebrowserUploadUrl = ‘../ckupload.php’; 即可

4,编写负责处理上传图片的php文件(这里采用php脚本,其他的什么同理),大概是这么一段代码

<?

$url = ‘../images/uploads/’.time().”_”.$_FILES[‘upload’][‘name’];

//extensive suitability check before doing anything with the file…
    if (($_FILES[‘upload’] == “none”) OR (empty($_FILES[‘upload’][‘name’])) )
    {
       $message = “No file uploaded.”;
    }
    else if ($_FILES[‘upload’][“size”] == 0)
    {
       $message = “The file is of zero length.”;
    }
    else if (($_FILES[‘upload’][“type”] != “image/pjpeg”) AND ($_FILES[‘upload’][“type”] != “image/jpeg”) AND ($_FILES[‘upload’][“type”] != “image/png”))
    {
       $message = “The image must be in either JPG or PNG format. Please upload a JPG or PNG instead.”;
    }
    else if (!is_uploaded_file($_FILES[‘upload’][“tmp_name”]))
    {
       $message = “You may be attempting to hack our server. We’re on to you; expect a knock on the door sometime soon.”;
    }
    else {
      $message = “”;
      $move = @ move_uploaded_file($_FILES[‘upload’][‘tmp_name’], $url);
      if(!$move)
      {
         $message = “Error moving uploaded file. Check the script is granted Read/Write/Modify permissions.”;
      }
      $url = “../” . $url;
    }
$funcNum = $_GET[‘CKEditorFuncNum’] ;
echo “<script type=’text/javascript’>window.parent.CKEDITOR.tools.callFunction($funcNum, ‘$url’, ‘$message’);</script>”;
?>
这样一来就oK啦

文章來源: http://yiming465.com/2016/05/15/ ... %E5%8A%9F%E8%83%BD/

回復

使用道具 舉報

您需要登錄後才可以回帖 登錄 | 立即註冊

本版積分規則

 ㄚ母滴雞湯
 員林香純滴雞精

Archiver|手機版|小黑屋|彰化一整天的論壇(Excel,Office)  |网站地图

GMT+8, 2018-1-17 18:57 , Processed in 0.044369 second(s), 12 queries , Apc On.

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表