php ckeditor图片上传

  1.  修改插件目录下的image.js  查找  Upload   修改hidden : false;     id:'Upload',hidden:true

  2. 配置ckeditor: 

    在ckeditor目录下的config.js 中添加配置

     

 config.image_previewText = ' ';
 config.filebrowserUploadUrl = "ckeditorUpload";

  

 3. 编写上传代码

//upload image from ckeditor
    public function upload(){
        $extensions = array("jpg","bmp","gif","png");
        $uploadFilename = $_FILES['upload']['name'];
        $extension = pathInfo($uploadFilename,PATHINFO_EXTENSION);
        if(in_array($extension,$extensions)){
            $uploadPath = str_replace("\\",'/',realpath(__ROOT__))."/uploads/";
            $uuid = str_replace('.','',uniqid("",TRUE)).".".$extension;
            $desname = $uploadPath.$uuid;
            $previewname = '/uploads/'.$uuid;
            $tag = move_uploaded_file($_FILES['upload']['tmp_name'],$desname);
            $callback = $_REQUEST["CKEditorFuncNum"];
            echo "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction
            ($callback,'".$previewname."','');</script>";
        }else{
          echo "<font color=\"red\"size=\"2\">*文件格式不正确(必须为.jpg/.gif/.bmp/.png文件)</font>";
        }
    }

   


注意:其中   接收图片文件:图片上传时的控件名为  upload , 还需接收一个参数  CKEditorFuncNum,


参考:http://blog.csdn.net/rongyongfeikai2/article/details/21327849font




/**
     * ckeditor上传图片
     */
    public function ckeditorUploadAction()
    {
        $request = \Make::request();

        $image =  isset($_FILES['upload']) ? $_FILES['upload'] : array(); ;

        $cKEditorFuncNum = $request->query->get('CKEditorFuncNum');
        //上传图片的参数
        $uploadParams = array(
            'maxSize'    => $this->getParameters('upload.image.maxsize'),
            'savePath'   => $this->getParameters('upload.image.paths'),
            'allowTypes' => $this->getParameters('upload.image.types'),
        );

        $uploadImage     = $this->get('UploadImage', array($image, $uploadParams));
        $uploadImageInfo = $uploadImage->getImageInfo();

        if ('SUCCESS' == $uploadImageInfo['status']) {
            $photo = array(
                'path'       => $uploadImageInfo['path'],
                'title'      => $uploadImageInfo['title'],
                'size'       => $uploadImageInfo['size'],
                'type'       => $uploadImageInfo['type'],
                'create_at'  => time(),
                'update_at'  => time(),
                'is_trash'   => 0,
            );
            $photoRepository = $this->getConnection('write')
                                    ->getRepository('Manager:Repository:Photo');
            $photoRepository->insert($photo);
            $imagePath = \Make::asset('uploads/images') . $uploadImageInfo['path'];

            return "<script type='text/javascript'>
            window.parent.CKEDITOR.tools.callFunction({$cKEditorFuncNum}, '{$imagePath}', '')
            </script>";
        } else {
            return "<script type='text/javascript'>
            window.parent.CKEDITOR.tools.callFunction({$cKEditorFuncNum}, '/',
                                                     '{$uploadImageInfo['status']}')
            </script>";
        }
    }


你可能感兴趣的:(PHP,上传图片,ckeditor)