composer require overtrue/flysystem-qiniu -vvv
composer require iidestiny/flysystem-oss -vvv
composer require overtrue/flysystem-cos -vvv
composer require isszz/think-filesystem-driver -vvv
在 config/filesystem.php 的 disks 里更改配置, 或者在.env内新增相关配置字段
<?php
return [
'disks' => [
// 七牛配置
'qiniu' => [
'type' => 'qiniu',
'access_key' => env('qiniu.access_key', 'xxxxxxxxxxxxxxxx'),
'secret_key' => env('qiniu.secret_key', 'xxxxxxxxxxxxxxxx'),
'bucket' => env('qiniu.bucket', 'test'),
'domain' => env('qiniu.domain', 'xxx.xxx.top'), // or host: https://xxxx.xxx.top
],
// 阿里 oss 配置
'oss' => [
'type' => 'oss',
'access_key' => env('oss.access_key', 'xxxxxxxxxxxxxxxx'),
'secret_key' => env('oss.secret_key', 'xxxxxxxxxxxxxxxx'),
'bucket' => env('oss.bucket', 'test'),
'domain' => env('oss.domain', 'xxx.xxx.top'), // ssl:https://xxxx.xxx.top
'is_cname' => env('oss.is_cname', false), // 如果 is_cname 为 false, domain 应配置 oss 提供的域名如:`oss-cn-beijing.aliyuncs.com`,cname 或 cdn 请自行到阿里 oss 后台配置并绑定 bucket
'root' => env('oss.root', ''), // 前缀,非必填
],
// 腾讯 cos 配置
'cos' => [
'type' => 'cos',
'region' => env('cos.region', 'ap-shanghai'), // 地域
'credentials' => [
'appId' => env('cos.app_id'), // 域名中数字部分
'secretId' => env('cos.secret_id'),
'secretKey' => env('cos.secret_key'),
],
'bucket' => env('cos.bucket'),
'cdn' => env('cos.cdn'), // CDN 域名
'scheme' => env('cos.scheme', 'https'),
'read_from_cdn' => env('cos.read_from_cdn', false),
'timeout' => env('cos.timeout', 60),
'connect_timeout' => env('cos.connect_timeout', 60),
],
// ...
]
];
[QINIU]
ACCESS_KEY = lekrgwlekgjwlekgjlmbdfbhererlkgjerlkgerl
SECRET_KEY = 4hjf9048t3823hfg8230984u9fj02389urg234ti
BUCKET = cfyun-img
DOMAIN = img.cfyun.cc
[OSS]
ACCESS_KEY = lekrgwlekgjwlekgjlmbdfbhererlkgjerlkgerl
SECRET_KEY = 4hjf9048t3823hfg8230984u9fj02389urg234ti
BUCKET = cfyun-img
DOMAIN = img.cfyun.cc
IS_NAME = false
[COS]
APP_ID = lekrgwlekgjwlekgjlmbdfbhererlkgjerlkgerl
SECRET_ID = 4hjf9048t3823hfg8230984u9fj02389urg234ti
SECRET_KEY = 4hjf9048t3823hfg8230984u9fj02389urg234ti
BUCKET = cfyun-img
cdn = img.cfyun.cc
use think\facade\Filesystem;
$disk = Filesystem::disk('qiniu');
// $disk = Filesystem::disk('oss');
// $disk = Filesystem::disk('cos');
// 按需引入插件, cos暂时无用
$disk->addPlugin();
$file = request()->file('file');
$filepath = $disk->putFile('mypath', $file);
// 插件提供的url获取
$url = $disk->getUrl($filepath);
dd([$filepath, $url]);
<form action="{{ url('index/upload') }}" method="post" enctype="multipart/form-data">
<input type="file" name="file">
<button type="submit">上传</button>
</form>
- 查看七牛更多用法: overtrue/flysystem-qiniu
- 查看OSS更多用法: iidestiny/flysystem-oss
- 查看COS更多用法: overtrue/flysystem-cos
- 查看Flysystem API: http://flysystem.thephpleague.com/api/