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.