thinkphp6整合文件上傳,七牛雲
composer下載包
# -vvv 可以試試的看到require進度
composer require death_satan/think-qiniu-storage -vvv
編輯 項目config目錄下的filesystem.php文件
<?php
use think\facade\Env;
return [
// 默認磁盤
'default' => Env::get('filesystem.driver', 'local'),
// 磁盤列表
'disks' => [
'local' => [
'type' => 'local',
'root' => app()->getRuntimePath() . 'storage',
],
'public' => [
// 磁盤類型
'type' => 'local',
// 磁盤路徑
'root' => app()->getRootPath() . 'public/storage',
// 磁盤路徑對應的外部URL路徑
'url' => '/storage',
// 可見性
'visibility' => 'public',
],
//newly added
'qiniu'=>[
'type'=>'qiniu',
'accessKey'=>'your accessKey',//你的accessKey
'secretKey'=>'your secretKey',//你的secretKey
'bucket'=>'your qiniu bucket name',//你的存儲空間名
'domain'=>'your qiniu bind domain' //你的七牛雲加速域名
]
// 更多的磁盤配置信息
],
];
配置完后在控制器中使用
<?php
namespace app\controller;
use app\BaseController;
class Index extends BaseController
{
public function index()
{
//獲取上傳文件
$image = $this->request->file('image');
//獲取上傳后的文件路徑
$qiniu_file = \think\facade\Filesystem::disk('qiniu')->putFile('image',$image);
dd($qiniu_file);
}
}