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); + } +}