百度编辑器的使用

模板页面代码

<script id="editor" name="Content" type="text/plain" style="width:1024px;height:500px;"></script>

<script type="text/javascript" src="/static/js/ueditor.config.js"></script>
<script type="text/javascript" src="/static/js/ueditor.all.min.js"></script>
<script type="text/javascript" src="/static/js/zh-cn.js"></script>
<script type="text/javascript">
    var ue = UE.getEditor('editor', {
        autoHeightEnabled: true,
        autoFloatEnabled: true,
        serverUrl: '{:url("editorUpload")}',
    });
</script>

后台PHP代码,调用文件需放到指定位置

    public function editorUpload()
    {
        date_default_timezone_set("Asia/chongqing");
        error_reporting(E_ERROR);
        header("Content-Type: text/html; charset=utf-8");

        $CONFIG = json_decode(preg_replace("/\/\*[\s\S]+?\*\//", "", file_get_contents("../app/admin/controller/UEditor/config.json")), true);
        $action = $_GET['action'];

        switch ($action) {
            case 'config':
                $result =  json_encode($CONFIG);
                break;

            /* 上传图片 */
            case 'uploadimage':
                /* 上传涂鸦 */
            case 'uploadscrawl':
                /* 上传视频 */
            case 'uploadvideo':
                /* 上传文件 */
            case 'uploadfile':
                $result = include("../app/admin/controller/UEditor/action_upload.php");
                break;

            /* 列出图片 */
            case 'listimage':
                $result = include("../app/admin/controller/UEditor/action_list.php");
                break;
            /* 列出文件 */
            case 'listfile':
                $result = include("../app/admin/controller/UEditor/action_list.php");
                break;

            /* 抓取远程文件 */
            case 'catchimage':
                $result = include("../app/admin/controller/UEditor/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;
        }
    }

 

posted @ 2018-05-30 16:31  小_奕  阅读(204)  评论(0)    收藏  举报