PHP code example of fgh151 / yii2-s3-upload

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

    

fgh151 / yii2-s3-upload example snippets


<?= 
'components' => [
    'storage' => [
        'class' => fgh151\yii2\s3upload\S3Storage::class,
        'key' => 's3-api-key',
        'secret' => 's3-api-secret',
        'bucket' => 'bucket-name'
        //You may also change region, provider, etc
    ],
] 

class FormModel extends \yii\db\ActiveRecord
{
    public $uploadImage;
    public $pathToImage;

    public function rules()
    {
        return [
            ['uploadImage', 'file', 'extensions' => ['png', 'jpg', 'jpeg']],
        ];
    }
    public function behaviors()
    {
        return [
            [
                'class' => fgh151\yii2\s3upload\S3UploadBehavior::class, //Behavior class
                'attribute' => 'uploadImage',
                'storageAttribute' => 'pathToImage', //Entity indefier in mapping clas
            ],
        ];
    }
    
    public function afterSave($insert,$changedAttributes){
        parent::afterSave($insert,$changedAttributes);
        if ($this->pathToImage !== null) {
            //TODO: save $this->pathToImage
        }
    }
}

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

php composer.phar