Yii2 solve Baidu editor umeditor picture upload problem ewebeditor editor download metaeditor editor Download Ewebeditor editor

Source: Internet
Author: User
Tags yii
Author: White Wolf Source: http://www.manks.top/article/yii2_umeditor_upload This article copyright belongs to the author, welcome reprint, but without the author's consent must retain this paragraph statement, and in the article page obvious location gives the original text connection, Otherwise, the right to pursue legal liability is retained.

YII2 Framework integrated Baidu Editor, because the file upload is Yii2 bring the uploadedfile, it is inevitable umeditor upload unsuccessful problem, solve the problem only need two steps, we look at the specific implementation

First we put the Umeditor configuration well, here only need to change the ImageUrl configuration item, we modify its point to/tools/um-upload

The next step is to implement the/tools/um-upload method,

In accordance with the implementation of the Ueditor, we only need to return success information here after the successful upload

 UseBackend\models\upload; UseYii\web\uploadedfile; /** * Baidu Umeditor upload*/ Publicfunctionactionumupload () {$model=NewUpload (); if(Yii::$app->request->isPost) {            $model-file= Uploadedfile::getinstance ($model, 'file ');$dir=' File save directory '; 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" and "="$model-file-BaseName, "url" =$dir, "Size" =$model-file->size, "type" = =$model-file->type, "state" and "="SUCCESS ",                ]; Exit(Json_encode ($info)); }          }    }

Special reminder: The state status of the returned $info information can only be success, case-sensitive

For yii image upload please refer to Yii2 file upload

About Yii Integration Baidu Editor please refer to YII2 integrated Baidu editor Umeditor

The above describes the YII2 to solve the Baidu editor umeditor picture upload problem, including editor, Baidu Editor content, I hope that the PHP tutorial interested in a friend has helped.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.