本地存储:
use League\Flysystem\Filesystem;
use League\Flysystem\Adapter\Local;
$adapter = new Local(__DIR__.'/path/to/root');
$localFilesystem = new Filesystem($adapter);
S3 存储:
use Aws\S3\S3Client;
use League\Flysystem\AwsS3v3\AwsS3Adapter;
use League\Flysystem\Filesystem;
$client = S3Client::factory([
'credentials' => [
'key' => 'your-key',
'secret' => 'your-secret',
],
'region' => 'your-region',
'version' => 'latest|version',
]);
$adapter = new AwsS3Adapter($client, 'your-bucket-name', 'optional/path/prefix');
$s3Filesystem = new Filesystem($adapter);
然后,用一个打开你的文件,然后写入另一个:
$contents = $localFilesystem->read('path/to/file.txt');
$s3Filesystem->write('path/to/file.txt', $contents);
您不需要要求、包含或评估任何内容!希望这可以帮助!