初始上传

This commit is contained in:
2026-04-04 17:27:12 +08:00
parent 4d80d28eb4
commit b7e11774ee
11191 changed files with 1588469 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
<h1><p align="center">thinkphp-filesystem-cloud</p></h1>
<p align="center"> thinkphp6.0 的文件系统扩展包支持上传阿里云OSS和七牛和腾讯云COS</p>
## 包含
1. php >= 7.1
2. thinkphp >=6.0.0
## 支持
1. 阿里云
2. 七牛云
3. 腾讯云
## 计划
1. 支持华为云
## 安装
第一步:
```shell
$ composer require thans/thinkphp-filesystem-cloud
```
第二步:
在config/filesystem.php中添加配置
```
'aliyun' => [
'type' => 'aliyun',
'accessId' => '******',
'accessSecret' => '******',
'bucket' => 'bucket',
'endpoint' => 'oss-cn-hongkong.aliyuncs.com',
'url' => 'http://oss-cn-hongkong.aliyuncs.com',//不要斜杠结尾此处为URL地址域名。
],
'qiniu' => [
'type' => 'qiniu',
'accessKey' => '******',
'secretKey' => '******',
'bucket' => 'bucket',
'url' => '',//不要斜杠结尾此处为URL地址域名。
],
'qcloud' => [
'type' => 'qcloud',
'region' => '***',
'appId' => '***', // 域名中数字部分
'secretId' => '***',
'secretKey' => '***',
'bucket' => '***',
'timeout' => 60,
'connect_timeout' => 60,
'cdn' => '您的 CDN 域名',
'scheme' => 'https',
'read_from_cdn' => false,
]
```
## 授权
MIT
## 感谢
1. thinkphp
2. xxtime/flysystem-aliyun-oss
3. liz/flysystem-qiniu
4. league/flysystem
5. overtrue/flysystem-cos

View File

@@ -0,0 +1,32 @@
{
"name": "thans/thinkphp-filesystem-cloud",
"description": "thinkphp6.0 filesystem,include Aliyun and Qiniu",
"type": "library",
"require": {
"php": ">=7.1.0",
"topthink/framework": "^6.0.0",
"xxtime/flysystem-aliyun-oss": "^1.4",
"liz/flysystem-qiniu": "^1.10",
"overtrue/flysystem-cos": "^2.0.0"
},
"license": "MIT",
"authors": [
{
"name": "Thans",
"email": "360641274@qq.com"
}
],
"minimum-stability": "dev",
"autoload": {
"psr-4": {
"thans\\filesystem\\": "src/"
}
},
"extra": {
"think": {
"services": [
"thans\\filesystem\\Service"
]
}
}
}

View File

@@ -0,0 +1,78 @@
<?php
namespace thans\filesystem;
use think\App;
use think\filesystem\Driver;
use think\helper\Arr;
class Filesystem
{
protected $disks;
/** @var App */
protected $app;
public function __construct(App $app)
{
$this->app = $app;
}
/**
* @param null|string $name
*
* @return Driver
*/
public function disk(string $name = null): Driver
{
$name = $name ?: $this->app->config->get('filesystem.default');
if (!isset($this->disks[$name])) {
$config = $this->app->config->get("filesystem.disks.{$name}");
$this->disks[$name] = App::factory($config['type'], '\\thans\\filesystem\\driver\\', $config);
}
return $this->disks[$name];
}
/**
* 获取缓存配置.
*
* @param null|string $name 名称
* @param mixed $default 默认值
*
* @return mixed
*/
public function getConfig(string $name = null, $default = null)
{
if (!is_null($name)) {
return $this->app->config->get('filesystem.'.$name, $default);
}
return $this->app->config->get('filesystem');
}
/**
* 获取磁盘配置.
*
* @param string $disk
* @param null $name
* @param null $default
*
* @return array
*/
public function getDiskConfig($disk, $name = null, $default = null)
{
if ($config = $this->getConfig("disks.{$disk}")) {
return Arr::get($config, $name, $default);
}
throw new InvalidArgumentException("Disk [$disk] not found.");
}
public function __call($method, $parameters)
{
return $this->disk()->$method(...$parameters);
}
}

View File

@@ -0,0 +1,11 @@
<?php
namespace thans\filesystem;
class Service extends \think\Service
{
public function register()
{
$this->app->bind('filesystem', Filesystem::class);
}
}

View File

@@ -0,0 +1,36 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
declare(strict_types=1);
namespace thans\filesystem\driver;
use League\Flysystem\AdapterInterface;
use thans\filesystem\traits\Storage;
use think\filesystem\Driver;
use Xxtime\Flysystem\Aliyun\OssAdapter;
class Aliyun extends Driver
{
use Storage;
protected function createAdapter(): AdapterInterface
{
$aliyun = new OssAdapter([
'accessId' => $this->config['accessId'],
'accessSecret' => $this->config['accessSecret'],
'bucket' => $this->config['bucket'],
'endpoint' => $this->config['endpoint'],
]);
return $aliyun;
}
}

View File

@@ -0,0 +1,46 @@
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2019 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: yunwuxin <448901948@qq.com>
// +----------------------------------------------------------------------
declare(strict_types=1);
namespace thans\filesystem\driver;
use League\Flysystem\Adapter\Local as LocalAdapter;
use League\Flysystem\AdapterInterface;
use thans\filesystem\traits\Storage;
use think\filesystem\Driver;
class Local extends Driver
{
use Storage;
/**
* 配置参数.
*
* @var array
*/
protected $config
= [
'root' => '',
];
protected function createAdapter(): AdapterInterface
{
$permissions = $this->config['permissions'] ?? [];
$links = ($this->config['links'] ?? null) === 'skip'
? LocalAdapter::SKIP_LINKS
: LocalAdapter::DISALLOW_LINKS;
return new LocalAdapter(
$this->config['root'], LOCK_EX, $links, $permissions
);
}
}

View File

@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace thans\filesystem\driver;
use League\Flysystem\AdapterInterface;
use Overtrue\Flysystem\Cos\CosAdapter;
use thans\filesystem\traits\Storage;
use think\filesystem\Driver;
class Qcloud extends Driver
{
use Storage;
protected function createAdapter(): AdapterInterface
{
$config = [
'region' => $this->config['region'],
'credentials' => [
'appId' => $this->config['appId'], // 域名中数字部分
'secretId' => $this->config['secretId'],
'secretKey' => $this->config['secretKey'],
],
'bucket' => $this->config['bucket'],
'timeout' => $this->config['timeout'] ?? 60,
'connect_timeout' => $this->config['connect_timeout'] ?? 60,
'cdn' => $this->config['cdn'],
'scheme' => $this->config['scheme'] ?? 'https',
'read_from_cdn' => $this->config['read_from_cdn'] ?? false,
];
return new CosAdapter($config);
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace thans\filesystem\driver;
use League\Flysystem\AdapterInterface;
use Liz\Flysystem\QiNiu\QiNiuOssAdapter;
use thans\filesystem\traits\Storage;
use think\filesystem\Driver;
class Qiniu extends Driver
{
use Storage;
protected function createAdapter(): AdapterInterface
{
$qiniu = new QiNiuOssAdapter($this->config['accessKey'], $this->config['secretKey'],
$this->config['bucket'], $this->config['url']);
return $qiniu;
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace thans\filesystem\traits;
trait Storage
{
public function getUrl(string $path)
{
if (strpos($path, '/') === 0) {
return $path;
}
return isset($this->config['url']) && $this->config['url'] ? $this->config['url'].DIRECTORY_SEPARATOR.$path
: $path;
}
}