Thinkphp 整合Ueditor 笔记

原文地址:https://blog.csdn.net/lcw2007101/article/details/51332002

使用以上链接前辈的代码,出现无法保存,以及无法显示图片问题。我保存的路径为根目录下的Uploads目录,现将代码贴至博客

上代码:

 <js file="__ROOT__/Lib/Ueditor/ueditor.config.js"/>
    <js file="__ROOT__/Lib/Ueditor/ueditor.all.min.js"/>
    
    
    <js file="__ROOT__/Lib/Ueditor/lang/zh-cn/zh-cn.js"/>
    <script type="text/javascript" charset="utf-8">
        window.UEDITOR_HOME_URL = "/images/";
        //window.UEDITOR_CONFIG.imagePath='__ROOT__/Uploads/GeekList/images/';
        window.UEDITOR_CONFIG.imageUrlPrefix='__ROOT__/Uploads/GeekList/images/';
        $(document).ready(function () {
            UE.getEditor('info', {
                initialFrameHeight: 300,
                initialFrameWidth: 600,
                serverUrl: "{:U(MODULE_NAME.'/Geeklist/save_info')}"

            });
        });

    script>

 

PHP部分:

 public function save_info(){
        $ueditor_config = json_decode(preg_replace("/\/\*[\s\S]+?\*\//", "", file_get_contents("./Lib/Ueditor/php/config.json")), true);
        $action = $_GET['action'];
        switch ($action) {
            case 'config':
                $result = json_encode($ueditor_config);
                break;
            /* 上传图片 */
            case 'uploadimage':
                /* 上传涂鸦 */
            case 'uploadscrawl':
                /* 上传视频 */
            case 'uploadvideo':
                /* 上传文件 */
            case 'uploadfile':
                $upload = new \Think\Upload();
                $upload->maxSize = 3145728;
                $upload->savePath = '/GeekList/images/';// 设置附件上传目录
                $upload->exts = array('jpg', 'gif', 'png', 'jpeg');
                $info = $upload->upload();
                if (!$info) {
                    $result = json_encode(array(
                        'state' => $upload->getError(),
                    ));
                } else {
                    //返回的路径
                    $url = __ROOT__."/Uploads" . $info["upfile"]["savepath"] . $info["upfile"]['savename'];

                    $result = json_encode(array(
                        'url' => $url,
                        'title' => htmlspecialchars($_POST['pictitle'], ENT_QUOTES),
                        'original' => $info["upfile"]['name'],
                        'state' => 'SUCCESS'
                    ));
                }
                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;
        }
    }

 

转载于:https://www.cnblogs.com/liyante/p/8950619.html

你可能感兴趣的:(php,json,javascript,ViewUI)