cakphp 2.0文件浏览器/上传器与CKEditor

时间:2016-07-19 12:11:04

标签: php cakephp ckeditor

我在cakePHP 2.0应用程序中使用ckeditor。我已经将它安装在我的app / webroot / js / ckeditor目录中。

ckeditor正在显示图片上传选项,并在config.js

中配置了这些行
 config.filebrowserImageBrowseUrl = '/app/webroot/ckeditor/pictures/';
 config.filebrowserImageUploadUrl = '/app/webroot/ckeditor/pictures/';

现在,图片上传界面看起来很好,但是当我点击"发送到服务器"按钮,图片无法上传到folder path

注意:将图像上传到文件夹的下一步是什么?

enter image description here enter image description here

2 个答案:

答案 0 :(得分:0)

您必须将它们链接到您的上传者

像这样

config.filebrowserBrowseUrl = BASE_URL + 'filebrowser/browse.php?type=files';
config.filebrowserImageBrowseUrl = BASE_URL + 'filebrowser/browse.php?type=images';
config.filebrowserFlashBrowseUrl = BASE_URL + 'filebrowser/browse.php?type=flash';
config.filebrowserUploadUrl = BASE_URL + 'filebrowser/upload.php?type=files';
config.filebrowserImageUploadUrl = BASE_URL + 'filebrowser/upload.php?type=images';
config.filebrowserFlashUploadUrl = BASE_URL + 'filebrowser/upload.php?type=flash';

答案 1 :(得分:0)

当您单击上传到服务器时,Ckeditor会在您的服务器上发送FileData。您必须在服务器上处理$ _FILES数据到给定路径,如@Ahmed Ebead所述。我在Yii2中使用这个:

  public function actionPublicUploadDrag(){
    return self::publicUpload(1);
}

public function actionPublicUploadBrowse(){
    /*prd(Yii::$app->request->get());*/
    return self::publicUpload(2);
}

// to provide browse facility
public function actionImageuploader(){
    //render your image browser page in this.
    exit;
}

private static function publicUpload($by = 1 ){

    $image = \yii\web\UploadedFile::getInstanceByName('upload');
    $destination = "@backend/web/img/public_image/";
    if($image){
        $images = Image::getImagine()->open($image->tempName);
        //saving original
        $imageName = time().$image->name;
       $saved = $image->saveAs(Yii::getAlias($destination). $imageName);
       if($saved){
        //{"fileName":"590860cae9734.jpg","uploaded":1,"url":"\/userfiles\/files\/Public%20Folder\/590860cae9734.jpg"}
            $uploadPath = \yii\helpers\Url::toRoute(['img/public_image/'],true);
        if($by == 1){
            return Json::encode(["fileName"=>$imageName,"uploaded"=>1,"url" => $uploadPath.'/'.$imageName]);
        }else if($by == 2 ){
            return "<script type='text/javascript'>window.parent.CKEDITOR.tools.callFunction('1', '$uploadPath/".$imageName."', 'Uploaded');</script>";
            }
       }
    }
    exit;
}