1.composer:
composer require lorine/oss-utils
2.控制器方法代码:
use Lorine\OssUtils\OssService;
function yun(){ $config = [ 'ak' => 'xxxxx',//SecretId /Access_Key 'sk' => 'xxxxx',//SecretKe /Secret_Key 'bucket' => 'xxx',//桶名 /空间名 'region' => 'ap-shanghai'//地区 七牛云为'',腾讯云在控制台对象存储界面获取,如上海(ap-shanghai) ]; try { //云存储类型 腾讯云:Tencent 七牛云:Qiniu $obj = (new OssService())->getOssService('Qiniu'); //$tmpName绝对路径 //$fileName自定义云储存的文件名称 //$res = $obj->uploadFile($config,$tmpName,$fileName); $res = $obj->uploadFile($config,'D:\phpstudy_pro\WWW\five\tp6\public\11111.png','123'); dd($res); }catch (Exception $exception){ dd($exception->getMessage()); } }
3.上传成功示例: