Home  >  Article  >  Backend Development  >  yii2 solves the problem of image upload in Baidu editor umeditor ewebeditor editor download metaeditor editor download ewebeditor editor upgrade

yii2 solves the problem of image upload in Baidu editor umeditor ewebeditor editor download metaeditor editor download ewebeditor editor upgrade

WBOY
WBOYOriginal
2016-07-29 08:51:561198browse

Author: Bailang Source: http://www.manks.top/article/yii2_umeditor_upload The copyright of this article belongs to the author, and you are welcome to reprint it. However, this statement must be retained without the author's consent, and a link to the original text must be provided in an obvious position on the article page. Otherwise, we reserve the right to pursue legal liability.

The yii2 framework integrates the Baidu editor. Because the file upload uses the UploadedFile that comes with yii2, it is inevitable that the umeditor upload will not be successful. To solve the problem, only two steps are needed. Let’s take a look at the specific implementation

First of all Let’s complete the configuration of ueditor first. Here we only need to change the imageUrl configuration item. We modify it to point to /tools/um-upload

Then the next step is to implement the /tools/um-upload method.

Follow ueditor From the perspective of implementation, here we only need to return success information after the upload is successful

use backend\models\Upload;
use yii\web\UploadedFile;
   /**
     *    百度umeditor上传
     */publicfunction actionUmUpload ()
    {
        $model = new Upload();

        if (Yii::$app->request->isPost) {

            $model->file = UploadedFile::getInstance($model, 'file');$dir = ‘文件保存目录’;
            if (!is_dir($dir))
                mkdir($dir);

            if ($model->validate()) {
                $fileName = $model->file->baseName . "." . $model->file->extension;$dir = $dir."/". $fileName;$model->file->saveAs($dir);

                $info = [
                    "originalName" => $model->file->baseName,
                    "name" => $model->file->baseName,
                    "url" => $dir,
                    "size" => $model->file->size,
                    "type" => $model->file->type,
                    "state" => "SUCCESS",                ];
                exit(json_encode($info));
            }  
        }
    }

Special reminder: the state in the $info information returned above can only be SUCCESS, which is case-sensitive

Please refer to Yii image upload Yii2 file upload

For information about yii integrating Baidu editor, please refer to yii2 integrating Baidu editor umeditor

The above introduces how yii2 solves the image upload problem of Baidu editor umeditor, including the content of editor and Baidu editor. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn