Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/nadar/yii2-s3
Yii 2 Amazon S3 Component
https://github.com/nadar/yii2-s3
Last synced: 29 days ago
JSON representation
Yii 2 Amazon S3 Component
- Host: GitHub
- URL: https://github.com/nadar/yii2-s3
- Owner: nadar
- Created: 2016-11-18T13:43:35.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2024-06-03T16:37:52.000Z (5 months ago)
- Last Synced: 2024-09-14T06:44:18.119Z (2 months ago)
- Language: PHP
- Homepage:
- Size: 123 KB
- Stars: 4
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Yii 2 Amazon S3 Component
This component allows you to work with the amazon AWS S3 buckets for uploading and finding files.
## Installation
Add the the package to your composer file:
```sh
composer require indielab/yii2s3
```Add the component to your application configuration file:
```php
'components' => [
// ...
's3' => [
'class' => \indielab\yii2s3\S3::class,
'bucket' => 'mybucket',
'key' => 'KEY',
'secret' => 'SECRET',
'region' => 'eu-central-1',
],
// ...
]
```## Usage
Using the component in order to upload a file:
```php
Yii::$app->s3->upload('path/to/the/file.jpg');
```Where file.jpg will be used as the key of the uploading file. Now in order to get the url to a key use:
```php
$url = Yii::$app->s3->url('file.jpg');
```### Configure Uploading
You can also provide more options to the uploading configuration method:
```php
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
]);
```