PHP code example of indielab / yii2s3

1. Go to this page and download the library: Download indielab/yii2s3 library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

indielab / yii2s3 example snippets


'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');

$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
]);