ueditor在使用时要确认自己项目中上传图片的方式(阿里云、腾讯云、还是直接上传到项目中),再在目录public\asset\admin\libs\ueditor\php\Uploader.class.php下修改上传方法: 1、上传阿里云
// $configEnv为阿里云配置参数
$keyId = $configEnv['ALIYUN_KEY_ID'];
$accessKey = $configEnv['ALIYUN_ACCESS_KEY'];
$endPoints=$configEnv['ALIYUN_ENDPOINT'];
$bucket = $configEnv['ALIYUN_BUCKET_NAME'];
$host = $configEnv['ALIYUN_CDN_NAME'];
try {
$oss = new OssClient($keyId, $accessKey, $endPoints);
$url = date('Ymd') . '_'. rand(1000,9999) . $this->fileType;
$oss->uploadFile($bucket,$url,$file['tmp_name']);
$this->fullName = $host . '/' . $url;
$this->stateInfo = 'SUCCESS';
} catch (\Exception $e) {
}
2、本地上传
//创建目录
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];
}
3、上传腾讯云
//$configEnv 为腾讯云配置参数
$ossClient = new Qcloud\Cos\Client(
[
'region' => $configEnv['QCLOUD_COS_REGION'],
'schema' => $configEnv['QCLOUD_COS_SCHEMA'], //协议头部,默认为http
'credentials'=> [
'secretId' => $configEnv['QCLOUD_COS_SECRET_ID'] ,
'secretKey' => $configEnv['QCLOUD_COS_SECRET_KEY']
]
]
);
$bucket = $configEnv['QCLOUD_COS_DEFAULT_BUCKET']; //存储桶名称 格式:BucketName-APPID
$filepath = $file["tmp_name"];
$file = fopen($filepath , "rb");
$fileKey = date('Ymd') . '/' . $this->fileName;
$result = $ossClient->putObject(
array(
'Bucket' => $bucket,
'Key' => $fileKey,
'Body' => $file
)
);
$this->fullName = $configEnv['QCLOUD_COS_cdn'] .'/'. $fileKey;
$this->stateInfo = 'SUCCESS';
修改之后就可以正确的上传图片了
|