PHP code example of mamadali / yii2-s3-storage

1. Go to this page and download the library: Download mamadali/yii2-s3-storage 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/ */

    

mamadali / yii2-s3-storage example snippets


    'components' => [
        ...
        's3storage' => [
            'class' => 'mamadali\S3Storage\components\S3Storage',
            'key' => // your access key
            'secret' => // your secret key
            'endpoint' => // your endpoint
            'default_bucket_name' => // your bucket name
            'bucket_domain' => // Optional: your bucket domain
        ],
        ...
    ];

    public function behaviors()
    {
        return [
            ...
            [
                'class' => StorageUploadBehavior::class,
                'attributes' => ['file'],
                'scenarios' => [self::SCENARIO_UPLOAD],
                'path' => 'path/model_class/{id}'
            ],
            ...
        ];
    }

    <?= $form->field($model, 'file')->fileInput() 

    $model->save();

S3Storage::formatUsageSpace(Yii::$app->s3storage->getTotalUsage());
// return "1 MB"

S3Storage::formatUsageSpace(Yii::$app->s3storage->getUsageByModelClass(Model::class));

Yii::$app->s3storage->getUsageSeperatedByModelClass();
/**
* return [
 *     [
 *          'model_class' => 'common\models\Model',
 *          'size' => 1048576 // bytes
 *     ],
 * ]
 */

php yii migrate/up --migrationPath=@vendor/mamadali/yii2-s3-storage/src/migrations