From 5cdfac03335d8dab9d430835e2d367aeff7872e6 Mon Sep 17 00:00:00 2001 From: augushong Date: Thu, 20 Aug 2026 22:12:41 +0800 Subject: [PATCH] =?UTF-8?q?feat(storage):=20=E6=96=B0=E5=A2=9ES3=E5=AD=98?= =?UTF-8?q?=E5=82=A8=E9=A9=B1=E5=8A=A8=E4=B8=8E=E7=A3=81=E7=9B=98=E9=85=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/filesystem.php | 7 +++++ extend/think/filesystem/driver/S3.php | 40 +++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) create mode 100644 extend/think/filesystem/driver/S3.php diff --git a/config/filesystem.php b/config/filesystem.php index 7b8b722..14cb807 100644 --- a/config/filesystem.php +++ b/config/filesystem.php @@ -44,6 +44,13 @@ return [ 'type' => 'Txcos', 'visibility' => 'public', ], + 's3' => [ + 'type' => 'S3', + 'visibility' => 'public', + ], + 'webdav' => [ + 'type' => 'Webdav', + ], // 更多的磁盘配置信息 ], ]; diff --git a/extend/think/filesystem/driver/S3.php b/extend/think/filesystem/driver/S3.php new file mode 100644 index 0000000..eb0c3f9 --- /dev/null +++ b/extend/think/filesystem/driver/S3.php @@ -0,0 +1,40 @@ + 'latest', + 'region' => sysconfig('upload', 's3_region'), + 'credentials' => [ + 'key' => sysconfig('upload', 's3_access_key'), + 'secret' => sysconfig('upload', 's3_secret_key'), + ], + ]; + + $endpoint = sysconfig('upload', 's3_endpoint'); + if (!empty($endpoint)) { + $options['endpoint'] = $endpoint; + if (sysconfig('upload', 's3_path_style') === '1') { + $options['use_path_style_endpoint'] = true; + } + } + + $client = new S3Client($options); + + return new AwsS3V3Adapter($client, sysconfig('upload', 's3_bucket')); + } + + public function url(string $path): string + { + return $this->concatPathToUrl(sysconfig('upload', 's3_domain'), $path); + } +}