一个配置文件
创建两个方法
1.上传方法
/** * 存储文件 * * @param $srcFile * @param $desFile * @throws Exception */public function storage_save($srcPath, $desPath){ //配置 $accessKeyId = ‘‘; $accessKeySecret = ‘‘; $endpoint = ‘‘; $bucket = ‘‘; $ossClient = new \OSS\OssClient($accessKeyId, $accessKeySecret, $endpoint); $ossClient->uploadFile($bucket, $desPath, $srcPath);}
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->getServiceLocator()->get(storage)->storage_save($data[‘tmp_name‘], $data[‘src‘]);
原文地址:https://www.cnblogs.com/yuuje/p/9300313.html
时间: 2024-10-12 04:28:44