PHP code example of oleg-chulakov-studio / yii2-filesaver

1. Go to this page and download the library: Download oleg-chulakov-studio/yii2-filesaver 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/ */

    

oleg-chulakov-studio / yii2-filesaver example snippets


    public function behaviors()
    {
        return [
            ....
            [
                'class' => FileSaverBehavior::className(),
                'group_type' => 'photo',
                'in_attribute' => 'photoFile',
                'out_attribute' => 'photo_id',
                'del_attribute' => 'photoDel',
                'allowedExtensions' => [
                    'png',
                    'jpeg',
                    'jpg'
                ]
            ],
            ...
        ];
    }
 

 /**
  * @var UploadedFile
 /**
 $photoFile;
 
  /**
   * @var boolean
  /**
 $photoDel;
 

$model = new TestModel();
$model->photoFile = new \sem\filestorage\adapters\RemoteFile($url);
$model->save();

 

$model = new TestModel();
$model->photoFile = UploadedFile::getInstance($model, 'photoFile');
$model->save();