PHP code example of mihaildev / yii2-file-upload

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

    

mihaildev / yii2-file-upload example snippets


	public function behaviors()
	{
		return [
			'file-upload' => [
				'class' => FileUploadBehavior::className(),
				/*
				'replacePairs' => [
					'<modelId>' => 'id',// данный набор установлен по умолчанию
				],
				*/
				'attributes' => [
					'file' =>[
						//'handler' => FileUploadBehavior::HANDLER_FILE, // установлен по умолчанию
						'path' => '@webroot/files/<modelId>/<fileName>.<fileExtension>',
						'url' => '@web/files/<modelId>/<fileName>.<fileExtension>',
					],
					'ava' => [
						'handler' => FileUploadBehavior::HANDLER_IMAGE,
						'path' => '@webroot/files/avatar/<modelId>/origin.<fileExtension>',
						'url' => '@web/files/avatar/<modelId>/origin.<fileExtension>',
						'imagine' => function($filename){
								return Image::aligning($filename, 800, 800);
							},
						'saveOptions'=> ['quality' => 90],
						'thumbs' => [
							'icon' => [
								'path' => '@webroot/files/avatar/<modelId>/icon.<fileExtension>',
								'url' => '@web/files/avatar/<modelId>/icon.<fileExtension>',
								'imagine' => function($filename){ return Image::thumbnail($filename, 50, 50);},
								'saveOptions'=> ['quality' => 70],
							],
							'preview' => [
								'path' => '@webroot/files/avatar/<modelId>/preview.<fileExtension>',
								'url' => '@web/files/avatar/<modelId>/preview.<fileExtension>',
								'imagine' => function($filename){ return Image::thumbnail($filename, 200, 200);},
								'saveOptions'=> ['quality' => 90],
							]
						]
					]
				]
			],
		];
	}

<?= $form->field($model, 'file')->widget(\mihaildev\fileupload\FileUploadWidget::className(),[
					'fileUrl' => $model->getUploadedFileUrl('file'),
					'fileName' => 'Скачать'
					]

				) 

<?= $form->field($model, 'ava')->widget(\mihaildev\fileupload\ImageUploadWidget::className(),[
					'imageOptions' => ['width' => '200'],
					'imageUrl' => $model->getUploadedFileUrl('ava', 'preview')
					]

				) 

php composer.phar 
json
"mihaildev/yii2-file-upload": "*"