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/ */
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
}
}
}