hello-my-gitee / think-filesystem
适用于thinkphp8的文件系统扩展,支持 Aliyun Qiniu COS OBS FTP GOOGLE QCloud S3 SFTP
v3.0.20
2025-06-14 17:23 UTC
Requires
- php: ^8.0.2
- league/flysystem: ^3.0
- league/flysystem-aws-s3-v3: ^3.0
- league/flysystem-ftp: ^3.0
- league/flysystem-google-cloud-storage: ^3.0
- league/flysystem-path-prefixing: ^3.3
- league/flysystem-read-only: ^3.3
- league/flysystem-sftp-v3: ^3.0
- overtrue/flysystem-cos: ^5.0.0
- overtrue/flysystem-qiniu: ^3.0
- topthink/framework: ^6.0|^8.0
- voku/portable-ascii: ^1.6.1|^2.0
- yzh52521/flysystem-obs: ^3.0
- yzh52521/flysystem-oss: ^3.0
Requires (Dev)
- symfony/http-foundation: ^6.0
This package is not auto-updated.
Last update: 2025-06-15 06:08:27 UTC
README
📣 本仓库克隆自github的yuanzhihai/think-filesystem 原作者长时间未更新, 本仓库现已将项目升级为兼容tp8可用,并提供长久更新支持
🔛 使用方式
composer require hello-my-gitee/think-filesystem
🆕 主要更新
- 兼容tp8 https://github.com/yuanzhihai/think-filesystem/pull/13#issue-2307486986
- getDiskConfig返回类型更改为mixed https://github.com/yuanzhihai/think-filesystem/pull/14#issue-2309477603
🫡 鸣谢:
- github原仓库 https://github.com/yuanzhihai/think-filesystem
- 原仓库PR提交者 https://github.com/hbh112233abc
👇 以下为原仓库内容文档
think-filesystem
thinkphp6.1 的文件系统扩展包,支持上传阿里云OSS和七牛和腾讯云COS和华为云OBS和awsS3
包含
- php >= 8.0.2
- thinkphp >=6.1.0
支持
- 阿里云
- 七牛云
- 腾讯云
- 华为云
- AwsS3
- ftp
- sftp
安装
第一步:
$ composer require yzh52521/think-filesystem
第二步: 在config/filesystem.php中添加配置
'aliyun' => [
'type' => 'aliyun',
'access_id' => '******',
'access_secret' => '******',
'bucket' => 'bucket',
'endpoint' => 'oss-cn-hongkong.aliyuncs.com',
'url' => 'http://oss-cn-hongkong.aliyuncs.com',
],
'qiniu' => [
'type' => 'qiniu',
'accessKey' => '******',
'secretKey' => '******',
'bucket' => 'bucket',
'domain' => '',
],
'qcloud' => [
'type' => 'qcloud',
'region' => '***', //bucket 所属区域 英文
'app_id' => '***', // 域名中数字部分
'secret_id' => '***',
'secret_key' => '***',
'bucket' => '***',
'timeout' => 60,
'connect_timeout' => 60,
'cdn' => '您的 CDN 域名',
'scheme' => 'https',
'read_from_cdn' => false,
]
'obs'=>[
'type' => 'obs',
'key' => 'OBS_ACCESS_ID',
'secret' => 'OBS_ACCESS_KEY', //Huawei OBS AccessKeySecret
'bucket' => 'OBS_BUCKET', //OBS bucket name
'endpoint' => 'OBS_ENDPOINT',
'cdn_domain' => 'OBS_CDN_DOMAIN',
'ssl_verify' => 'OBS_SSL_VERIFY', //true or false...
'debug' => 'APP_DEBUG',//true or false...
],
's3'=>[
'type' => 's3',
'credentials' => [
'key' => 'S3_KEY',
'secret' => 'S3_SECRET',
],
'region' => 'S3_REGION',
'version' => 'latest',
'bucket_endpoint' => false,
'use_path_style_endpoint' => false,
'endpoint' => 'S3_ENDPOINT',
'bucket_name' => 'S3_BUCKET',
],
'google'=>[
'type' =>'google',
'projectId' => 'GOOGLE_PROJECT_ID',//your-project-id
'bucket' => 'GOOGLE_BUCKET', //your-bucket-name
'prefix' => '',//optional-prefix
],
'ftp'=[
'type' =>'ftp',
'host' => 'example.com',
'username' => 'username',
'password' => 'password',
// 可选的 FTP 设置
// 'port' => 21,
// 'root' => '',
// 'passive' => true,
// 'ssl' => true,
// 'timeout' => 30,
'url'=>''
],
'sftp'=>[
'type'=> 'sftp',
'host' => 'example.com',
// 基于基础的身份验证设置...
'username' => 'username',
'password' => 'password',
// 使用加密密码进行基于 SSH 密钥的身份验证的设置...
'privateKey' => 'path/to/or/contents/of/privatekey',
'passphrase' => 'passphrase-for-privateKey',
// 可选的 SFTP 设置
'port' => 22,
'root' => '/path/to/root',
'url' => '/path/to/root',
'timeout' => 10
]
第三步: 开始使用。 请参考thinkphp文档 文档地址:https://www.kancloud.cn/manual/thinkphp6_0/1037639
demo
$file = $this->request->file( 'image' );
try {
validate(
['image' => [
// 限制文件大小(单位b),这里限制为4M
'fileSize' => 10 * 1024 * 1000,
// 限制文件后缀,多个后缀以英文逗号分割
'fileExt' => 'gif,jpg,png,jpeg'
]
])->check( ['image' => $file] );
$path = \yzh52521\filesystem\facade\Filesystem::disk( 'public' )->putFile( 'test',$file);
$url = \yzh52521\filesystem\facade\Filesystem::disk( 'public' )->url( $path );
return json( ['path' => $path,'url' => $url] );
} catch ( \think\exception\ValidateException $e ) {
echo $e->getMessage();
}
授权
MIT
感谢
- thinkphp
- overtrue/flysystem-qiniu
- league/flysystem
- overtrue/flysystem-cos