mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-08-30 04:35:33 +08:00
41 lines
1.1 KiB
PHP
41 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace think\filesystem\driver;
|
|
|
|
use Aws\S3\S3Client;
|
|
use League\Flysystem\AwsS3V3\AwsS3V3Adapter;
|
|
use League\Flysystem\FilesystemAdapter;
|
|
use think\filesystem\Driver;
|
|
|
|
class S3 extends Driver
|
|
{
|
|
protected function createAdapter(): FilesystemAdapter
|
|
{
|
|
$options = [
|
|
'version' => '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);
|
|
}
|
|
}
|