1. Go to this page and download the library: Download sergmoro1/yii2-uploader 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/ */
sergmoro1 / yii2-uploader example snippets
use sergmoro1\uploader\behaviors\HaveFileBehavior;
class User extends ActiveRecord
{
/**
* @inheritdoc
*/
public function behaviors()
{
return array_merge(parent::behaviors(), [
[
'class' => HaveFileBehavior::className(),
'file_path' => '/user/',
//'check_wh' => false, // not checking min width and height of image
'sizes' => [
//'original' => ['width' => 0, 'height' => 0, 'catalog' => 'original'], // zero values mean not resize
'original' => ['width' => 1200, 'height' => 1200, 'catalog' => 'original'],
'main' => ['width' => 400, 'height' => 400, 'catalog' => ''],
'thumb' => ['width' => 90, 'height' => 90, 'catalog' => 'thumb'],
],
],
]);
}
}
$model = User::findOne(2);
// get top thumb image of the model with image description
echo Html::img($model->getImage('thumb'), ['alt' => $model->getFileDescription()) ]);
// get top image of the model from main catalog
echo Html::img($model->getImage());
// get all images of the model from original catalog with image description
$image = $model->getImage('original');
while ($image) {
echo Html::img($image, ['title' => $model->getFileDescription()]);
$image = $model->getNextImage('original');
}