├── .DS_Store ├── ._.DS_Store ├── src ├── Service.php ├── traits │ └── Storage.php ├── driver │ ├── Qiniu.php │ ├── Qcloud.php │ ├── Aliyun.php │ └── Local.php └── Filesystem.php ├── composer.json └── README.md /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QThans/thinkphp-filesystem-cloud/HEAD/.DS_Store -------------------------------------------------------------------------------- /._.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/QThans/thinkphp-filesystem-cloud/HEAD/._.DS_Store -------------------------------------------------------------------------------- /src/Service.php: -------------------------------------------------------------------------------- 1 | app->bind('filesystem', Filesystem::class); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/traits/Storage.php: -------------------------------------------------------------------------------- 1 | config['url']) && $this->config['url'] ? $this->config['url'].DIRECTORY_SEPARATOR.$path 14 | : $path; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/driver/Qiniu.php: -------------------------------------------------------------------------------- 1 | config['accessKey'], $this->config['secretKey'], 17 | $this->config['bucket'], $this->config['url']); 18 | 19 | return $qiniu; 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "thans/thinkphp-filesystem-cloud", 3 | "description": "thinkphp6.0 filesystem,include Aliyun and Qiniu", 4 | "type": "library", 5 | "require": { 6 | "php": ">=7.1.0", 7 | "topthink/framework": "^6.0.0", 8 | "xxtime/flysystem-aliyun-oss": "^1.4", 9 | "liz/flysystem-qiniu": "^1.10", 10 | "overtrue/flysystem-cos": "^2.0.0" 11 | }, 12 | "license": "MIT", 13 | "authors": [ 14 | { 15 | "name": "Thans", 16 | "email": "360641274@qq.com" 17 | } 18 | ], 19 | "minimum-stability": "dev", 20 | "autoload": { 21 | "psr-4": { 22 | "thans\\filesystem\\": "src/" 23 | } 24 | }, 25 | "extra": { 26 | "think": { 27 | "services": [ 28 | "thans\\filesystem\\Service" 29 | ] 30 | } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/driver/Qcloud.php: -------------------------------------------------------------------------------- 1 | $this->config['region'], 20 | 'credentials' => [ 21 | 'appId' => $this->config['appId'], // 域名中数字部分 22 | 'secretId' => $this->config['secretId'], 23 | 'secretKey' => $this->config['secretKey'], 24 | ], 25 | 'bucket' => $this->config['bucket'], 26 | 'timeout' => $this->config['timeout'] ?? 60, 27 | 'connect_timeout' => $this->config['connect_timeout'] ?? 60, 28 | 'cdn' => $this->config['cdn'], 29 | 'scheme' => $this->config['scheme'] ?? 'https', 30 | 'read_from_cdn' => $this->config['read_from_cdn'] ?? false, 31 | ]; 32 | 33 | return new CosAdapter($config); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/driver/Aliyun.php: -------------------------------------------------------------------------------- 1 | 11 | // +---------------------------------------------------------------------- 12 | declare(strict_types=1); 13 | 14 | namespace thans\filesystem\driver; 15 | 16 | use League\Flysystem\AdapterInterface; 17 | use thans\filesystem\traits\Storage; 18 | use think\filesystem\Driver; 19 | use Xxtime\Flysystem\Aliyun\OssAdapter; 20 | 21 | class Aliyun extends Driver 22 | { 23 | use Storage; 24 | 25 | protected function createAdapter(): AdapterInterface 26 | { 27 | $aliyun = new OssAdapter([ 28 | 'accessId' => $this->config['accessId'], 29 | 'accessSecret' => $this->config['accessSecret'], 30 | 'bucket' => $this->config['bucket'], 31 | 'endpoint' => $this->config['endpoint'], 32 | ]); 33 | 34 | return $aliyun; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/driver/Local.php: -------------------------------------------------------------------------------- 1 | 11 | // +---------------------------------------------------------------------- 12 | declare(strict_types=1); 13 | 14 | namespace thans\filesystem\driver; 15 | 16 | use League\Flysystem\Adapter\Local as LocalAdapter; 17 | use League\Flysystem\AdapterInterface; 18 | use thans\filesystem\traits\Storage; 19 | use think\filesystem\Driver; 20 | 21 | class Local extends Driver 22 | { 23 | use Storage; 24 | /** 25 | * 配置参数. 26 | * 27 | * @var array 28 | */ 29 | protected $config 30 | = [ 31 | 'root' => '', 32 | ]; 33 | 34 | protected function createAdapter(): AdapterInterface 35 | { 36 | $permissions = $this->config['permissions'] ?? []; 37 | 38 | $links = ($this->config['links'] ?? null) === 'skip' 39 | ? LocalAdapter::SKIP_LINKS 40 | : LocalAdapter::DISALLOW_LINKS; 41 | 42 | return new LocalAdapter( 43 | $this->config['root'], LOCK_EX, $links, $permissions 44 | ); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 |
thinkphp-filesystem-cloud
3 |thinkphp6.0 的文件系统扩展包,支持上传阿里云OSS和七牛和腾讯云COS
4 | 5 | ## 包含 6 | 7 | 1. php >= 7.1 8 | 2. thinkphp >=6.0.0 9 | 10 | ## 支持 11 | 12 | 1. 阿里云 13 | 2. 七牛云 14 | 3. 腾讯云 15 | 16 | ## 计划 17 | 1. 支持华为云 18 | 19 | ## 安装 20 | 第一步: 21 | ```shell 22 | $ composer require thans/thinkphp-filesystem-cloud 23 | ``` 24 | 第二步: 25 | 在config/filesystem.php中添加配置 26 | 27 | ``` 28 | 'aliyun' => [ 29 | 'type' => 'aliyun', 30 | 'accessId' => '******', 31 | 'accessSecret' => '******', 32 | 'bucket' => 'bucket', 33 | 'endpoint' => 'oss-cn-hongkong.aliyuncs.com', 34 | 'url' => 'http://oss-cn-hongkong.aliyuncs.com',//不要斜杠结尾,此处为URL地址域名。 35 | ], 36 | 'qiniu' => [ 37 | 'type' => 'qiniu', 38 | 'accessKey' => '******', 39 | 'secretKey' => '******', 40 | 'bucket' => 'bucket', 41 | 'url' => '',//不要斜杠结尾,此处为URL地址域名。 42 | ], 43 | 'qcloud' => [ 44 | 'type' => 'qcloud', 45 | 'region' => '***', //bucket 所属区域 英文 46 | 'appId' => '***', // 域名中数字部分 47 | 'secretId' => '***', 48 | 'secretKey' => '***', 49 | 'bucket' => '***', 50 | 'timeout' => 60, 51 | 'connect_timeout' => 60, 52 | 'cdn' => '您的 CDN 域名', 53 | 'scheme' => 'https', 54 | 'read_from_cdn' => false, 55 | ] 56 | ``` 57 | 58 | 第三步: 59 | 开始使用。 60 | 请参考thinkphp文档 61 | 文档地址:[https://www.kancloud.cn/manual/thinkphp6_0/1037639 ](https://www.kancloud.cn/manual/thinkphp6_0/1037639 ) 62 | 63 | 64 | ## 授权 65 | 66 | MIT 67 | 68 | ## 感谢 69 | 1. thinkphp 70 | 2. xxtime/flysystem-aliyun-oss 71 | 3. liz/flysystem-qiniu 72 | 4. league/flysystem 73 | 5. overtrue/flysystem-cos 74 | -------------------------------------------------------------------------------- /src/Filesystem.php: -------------------------------------------------------------------------------- 1 | driver($name); 21 | } 22 | 23 | protected function resolveType(string $name) 24 | { 25 | return $this->getDiskConfig($name, 'type', 'local'); 26 | } 27 | 28 | protected function resolveConfig(string $name) 29 | { 30 | return $this->getDiskConfig($name); 31 | } 32 | 33 | /** 34 | * 获取缓存配置 35 | * @access public 36 | * @param null|string $name 名称 37 | * @param mixed $default 默认值 38 | * @return mixed 39 | */ 40 | public function getConfig(string $name = null, $default = null) 41 | { 42 | if (!is_null($name)) { 43 | return $this->app->config->get('filesystem.' . $name, $default); 44 | } 45 | 46 | return $this->app->config->get('filesystem'); 47 | } 48 | 49 | /** 50 | * 获取磁盘配置 51 | * @param string $disk 52 | * @param null $name 53 | * @param null $default 54 | * @return array 55 | */ 56 | public function getDiskConfig($disk, $name = null, $default = null) 57 | { 58 | if ($config = $this->getConfig("disks.{$disk}")) { 59 | return Arr::get($config, $name, $default); 60 | } 61 | 62 | throw new InvalidArgumentException("Disk [$disk] not found."); 63 | } 64 | 65 | /** 66 | * 默认驱动 67 | * @return string|null 68 | */ 69 | public function getDefaultDriver() 70 | { 71 | return $this->getConfig('default'); 72 | } 73 | 74 | /** 75 | * 动态调用 76 | * @param string $method 77 | * @param array $parameters 78 | * @return mixed 79 | */ 80 | public function __call($method, $parameters) 81 | { 82 | return $this->driver()->$method(...$parameters); 83 | } 84 | } --------------------------------------------------------------------------------