php将图片存储在阿里云oss存储上
创建两个方法
1.上传方法
1use OSS\OssClient; 2use think\Config; 3use OSS\Core\OssException; 4/** 5 * 存储文件 6 * 7 * @param $srcFile 8 * @param $desFile 9 * @throws Exception10*/11publicfunction storage_save($srcPath, $desPath)
12 { //配置
13$accessKeyId = '';
14$accessKeySecret = '';
15$endpoint = '';
16$bucket = '';
17
18$ossClient = new \OSS\OssClient($accessKeyId, $accessKeySecret, $endpoint);
19
20$ossClient->uploadFile($bucket, $desPath, $srcPath);
21 }
2.删除方法
/**
* 删除文件
*
* @param $srcFile 文件路径
*
*/
public function storage_delete($desPath)
{
//配置
$accessKeyId = '';
$accessKeySecret = '';
$endpoint = '';
$bucket = '';
$ossClient = new \OSS\OssClient($accessKeyId, $accessKeySecret, $endpoint);
$ossClient->deleteObject($bucket, $desPath);
}
方法的使用
/* $data["tmp_name"]=>"/work/web/shop/public/upload/goods/2018/07/phptQIOdq_5b470a5b98bef8_60278656.jpg" //本地文件地址
$data["src"]=> "upload/goods/2018/07/phptQIOdq_5b470a5b98bef8_60278656.jpg" //上传后的图片文件
*/
//上传阿里云OSS存储
$this->storage_save($data['tmp_name'], $data['src']);
以上是 php将图片存储在阿里云oss存储上 的全部内容, 来源链接: utcz.com/z/508582.html