Yii2 solves the problem of Baidu editor umeditor Image uploading-author of the White Wolf stack: White Wolf Source: Ghost.
The yii2 Framework integrates the Baidu editor. because the file is uploaded using the UploadedFile provided by yii2, the umeditor Upload will inevitably fail. to solve the problem, only two steps are required, let's take a look at the specific implementation
First, we need to configure umeditor. here we only need to change the imageUrl configuration item. we can modify it to point to/tools/um-upload.
The next step is to implement the/tools/um-upload method,
According to the ueditor implementation, we only need to return the successful message after the upload is successful.
Use backend \ models \ Upload; use yii \ web \ UploadedFile;/*** Baidu umeditor Upload */public function actionUmUpload () {$ model = new Upload (); 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" => $ model-> file-> baseName, "url" => $ dir, "size" => $ model-> file-> size, "type" =>$ model-> file-> type, "state" => "SUCCESS",]; exit (json_encode ($ info ));}}}
Note: in the $ info returned above, the state can only be SUCCESS, case sensitive.
For more information about Yii image upload, see Yii2 file upload.
For more information about yii integration Baidu editor, see yii2 integration Baidu editor umeditor