ueditor百度富文本版本:1.4.3
yii2七牛云SDK:yii2安装及使用七牛云文件上传
第一步
打开/web/ueditor/php/Uploader.class.php文件在最顶部引入“yii2安装及使用七牛云文件上传”内composer安装的七牛云类库
require(__DIR__ . '/../../../vendor/crazyfd/yii2-qiniu/Qiniu.php');
use crazyfd\qiniu\Qiniu;
第二步
修改/web/ueditor/php/Uploader.class.php内upFile方法
/**
* 上传文件的主处理方法
* @return mixed
*/
private function upFile()
{
$file = $this->file = $_FILES[$this->fileField];
if (!$file) {
$this->stateInfo = $this->getStateInfo("ERROR_FILE_NOT_FOUND");
return;
}
if ($this->file['error']) {
$this->stateInfo = $this->getStateInfo($file['error']);
return;
} else if (!file_exists($file['tmp_name'])) {
$this->stateInfo = $this->getStateInfo("ERROR_TMP_FILE_NOT_FOUND");
return;
} else if (!is_uploaded_file($file['tmp_name'])) {
$this->stateInfo = $this->getStateInfo("ERROR_TMPFILE");
return;
}
$this->oriName = $file['name'];
$this->fileSize = $file['size'];
//原始上传本地方法
$this->fileType = $this->getFileExt();
$this->fullName = $this->getFullName();
$this->filePath = $this->getFilePath();
$this->fileName = $this->getFileName();
$dirname = dirname($this->filePath);
//检查文件大小是否超出限制
if (!$this->checkSize()) {
$this->stateInfo = $this->getStateInfo("ERROR_SIZE_EXCEED");
return;
}
//检查是否不允许的文件格式
if (!$this->checkType()) {
$this->stateInfo = $this->getStateInfo("ERROR_TYPE_NOT_ALLOWED");
return;
}
//创建目录失败
if (!file_exists($dirname) && !mkdir($dirname, 0777, true)) {
$this->stateInfo = $this->getStateInfo("ERROR_CREATE_DIR");
return;
} else if (!is_writeable($dirname)) {
$this->stateInfo = $this->getStateInfo("ERROR_DIR_NOT_WRITEABLE");
return;
}
//重要代码
//移动文件
if (!(move_uploaded_file($file["tmp_name"], $this->filePath) && file_exists($this->filePath))) { //移动失败
$this->stateInfo = $this->getStateInfo("ERROR_FILE_MOVE");
} else { //移动成功
$this->stateInfo = $this->stateMap[0];
}
$accessKey ='';
$secretKey = '';
//资源访问域名(在七牛云内配置域名)
$domain = '';
//空间名
$bucket = '';
//七牛云文件路径
$qiniufilePath='website/'.date('Ymd',time()).'/';
$key=$qiniufilePath.$this->fileName;
//转存七牛云
$qiniu = new Qiniu($accessKey, $secretKey,$domain, $bucket);
$filePath = $this->filePath;
$qiniu->uploadFile($filePath,$key);
$url1 = $qiniu->getLink($key);
$this->fullName=$url1;
//删除本地图片
unlink($filePath);
}