没有安装百度编辑器的先通过下面地址安装:
https://github.com/BigKuCha/yii2-ueditor-widget
安装腾讯云对象存储的扩展:
https://github.com/q490880/yii2-qcloud-cos
修改 vendor\kucha\ueditor\UEditorAction.php的upFile方法
注释掉原来的上传代码
// if (!(move_uploaded_file($file["tmp_name"], $this->filePath) && file_exists($this->filePath))) { //移动失败 // $this->stateInfo = $this->getStateInfo("ERROR_FILE_MOVE"); // } else { //移动成功 // $this->fullName = $result; // $this->stateInfo = $this->stateMap[0]; // }换成:
$uploadResult = \Yii::$app->cos->upload($file["tmp_name"],$this->filePath); if($uploadResult['message'] == 'SUCCESS'){ $this->fullName = $uploadResult['data']['source_url']; $this->stateInfo = $this->stateMap[0]; }else{ $this->stateInfo = $this->getStateInfo("ERROR_FILE_MOVE"); }
修改vendor\kucha\ueditor\UEditorAction.php的handleAction
注释掉
// if (substr($result['url'], 0, 1) != '/') { // result['url'] = '/' . $result['url']; // } // $result['url'] = Yii::getAlias('@web'.$result['url']);