三步走 (1)composer安装扩展
composer require death_satan/think-qiniu-storage -vvv
composer require "overtrue/laravel-filesystem-qiniu" -vvv
(2)项目config目录下的filesystem.php文件下增加七牛云的配置
<?php
<?php
return [
'default' => env('filesystem.driver', 'local'),
'disks' => [
'local' => [
'type' => 'local',
'root' => app()->getRuntimePath() . 'storage',
],
'public' => [
'type' => 'local',
'root' => app()->getRootPath() . 'public/storage',
'url' => '/storage',
'visibility' => 'public',
],
'qiniu'=>[
'type'=>'qiniu',
'accessKey'=>'*',
'secretKey'=>'*',
'bucket'=>'*',
'domain'=>'*'
]
],
];
(3)控制器获取文件执行上传
$image = \request()->file('cover');
$qiniu_file = \think\facade\Filesystem::disk('qiniu')->putFile('image',$image);
return json(['code'=>200,'msg'=>'成功','data'=>$qiniu_file]);
|