Yii2 UEditor+七牛云存储

首先下载UEditor扩展。

composer require yidashi/yii2-ueditor

控制器中添加actions

public function actions()
    {
        return [
            'upload' => [
                'class' => 'kucha\ueditor\UEditorAction',
            ],
        ];
    }

在视图中引用UEditor

$form->field($model,'content')->widget('kucha\ueditor\UEditor',[]);

集成七牛PHP-SDK 查看详情

修改Uploader文件,文件目录vendor/yidashi/yii2-ueditor/Uploader.php文件upFile()函数。

//移动文件
        if (!(move_uploaded_file($file["tmp_name"], $this->filePath) && file_exists($this->filePath))) { //移动失败
            $this->stateInfo = $this->getStateInfo("ERROR_FILE_MOVE");
        } else { //移动成功
            $accessKey = Yii::$app->params['qiniuAccessKey'];
            $secretKey = Yii::$app->params['qiniuSecretKey'];
            $auth = new Auth($accessKey, $secretKey);
            $bucket = Yii::$app->params['qiniuBucket'];
            $token  = $auth->uploadToken($bucket);
            $key    = "upload/image/".date('Ymd',time())."/".$this->fileName;
            $uploadMgr = new UploadManager();
            list($ret, $err) = $uploadMgr->putFile($token, $key, $this->filePath);
            $this->stateInfo = $this->stateMap[0];
        }