修改插件目錄下的image.js 查找 Upload 修改hidden : false; id:'Upload',hidden:truejavascript
配置ckeditor: php
在ckeditor目錄下的config.js 中添加配置java
config.image_previewText = ' '; config.filebrowserUploadUrl = "ckeditorUpload";
3. 編寫上傳代碼ui
//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 ,this
參考:http://blog.csdn.net/rongyongfeikai2/article/details/21327849 fontspa
/** * 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>"; } }