今天学习用ThinkPHP加入UEditor,开始时始终有问题,一直提示“选择保存目录:正在读取目录”,如下:

QQ图片20150314222320.jpg

        检查代码:

<script type="text/javascript">
        window.UEDITOR_HOME_URL = "__ROOT__/Data/ueditor/";
        window.onload=function(){
            window.UEDITOR_CONFIG.initialFrameWidth=1100;   //设置ueditor的宽度
            window.UEDITOR_CONFIG.initialFrameHeight=600;   //设置ueditor的高度
            window.UEDITOR_CONFIG.imageUrl = "{:U(GROUP_NAME . '/Blog/upload')}";   //图片上传提交地址
            window.UEDITOR_CONFIG.imagePath = "__ROOT__/Uploads/";      //图片修正地址,引用了fixedImagePath
            UE.getEditor('content');        //里面的content是textarea的id值
        }
    </script>

         后来才找到要加入一条:window.UEDITOR_CONFIG.savePath = ['']; 否则没有保存目录就上传不了图片。

import('ORG.Net.UploadFile');
        $upload=new UploadFile();       // 实例化上传类
        $upload->allowExts = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
        $upload->autoSub=true;
        $upload->subType='date';
        $upload->dateFormat='Ymd';
        $upload->savePath = './Uploads/';// 设置附件上传目录

        if($upload->upload()){
            $info=$upload->getUploadFileInfo();
            echo json_encode(array(
                'url' => $info[0]['savename'],
                'title' => htmlspecialchars($_POST['pictitle'], ENT_QUOTES),
                'original' => $info[0]['name'],
                'state' => 'Success'
                ));
        }else{
            echo json_encode(array(
                'state' => $upload->getErrorMsg()
                ));
        }
        上面是PHP的上传代码,比较简单,不过开始时我写的import是import('ORG.Util.Net.UploadFile');,多了个Util害了一个下午时间在错。。。