indielab / yii2s3
此包的最新版本(2.0.0)没有可用的许可证信息。
Yii 2 S3 组件
2.0.0
2024-05-11 20:18 UTC
Requires
- php: ^8.2
- aws/aws-sdk-php: ^3.0
- yiisoft/yii2: ^2.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.40
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^11.1
- rector/rector: ^1.0
This package is auto-updated.
Last update: 2024-09-03 17:13:41 UTC
README
该组件允许您处理 Amazon AWS S3 存储桶以上传和查找文件。
安装
将包添加到您的 composer 文件中
composer require indielab/yii2s3
将组件添加到您的应用程序配置文件中
'components' => [ // ... 's3' => [ 'class' => \indielab\yii2s3\S3::class, 'bucket' => 'mybucket', 'key' => 'KEY', 'secret' => 'SECRET', 'region' => 'eu-central-1', ], // ... ]
使用方法
使用组件上传文件
Yii::$app->s3->upload('path/to/the/file.jpg');
其中 file.jpg 将用作上传文件的键。现在要获取键的 URL,请使用
$url = Yii::$app->s3->url('file.jpg');
配置上传
您还可以向上传配置方法提供更多选项
Yii::$app->s3->upload('path/to/the/file.jpg', [ 'override' => true, // whether existing file should be overriden or not 'Key' => 'CacheControlTestFile.txt', // Define a specific name for the file instead of the source file name 'CacheControl' => 'max-age=' . strtotime('+1 year') // Add cache controler options ]);