We are going to deploy the new yiiframework.com website on March 23, 2018 from 8:00 to 12:00 UTC.
Website and Yii documentation will not be available in this time frame. Check the news for more details.

Yii 2.0: yii2-easy-uploader

easy way to upload image

github url


Report an issue



an easy way for make folders and upload images or file everywhere


The preferred way to install this extension is through composer.

Either run

composer.phar require  gomonkey/yii2-easy-uploader "*"

or add

"gomonkey/yii2-easy-uploader": "*"

to the require section of your composer.json file.


Add in your config file ( common/config/main.php )

'components' => [
        'uploaders' => [
            'class' => 'gomonkey\uploader\uploader',
            'baseFrontendUrl' => '/add_your_path/frontend/web/images',
            'baseBackendUrl' => '/add_your_path/backend/web/images',
            'rename' => true,
            'remove' => true, // Remove the original file
            'folders' => [
                    'name' => '1200',
                    'quality' => 70,
                    'width' => 1200
                    'name' => '800',
                    'quality' => 70,
                    'width' => 800
                    'name' => '600',
                    'quality' => 70,
                    'width' => 600
                    'name' => 'avatars',
                    'quality' => 70,
                    'width' => 200

if you use basic template, you can still use the same code above, just put the code in you config file and change baseFrontendUrl. You can remove or comment baseBackendUrl

In your controller action :

$upload = new Yii::$app->uploaders();
If you want to use backend path:
$upload = new Yii::$app->uploaders("backend");
$model->image =  $upload->upload( UploadedFile::getInstance($model, 'image'), "avatars" );

$model->image will have now the name of the uploaded image.

You can make infinite folders. For example with user id: images/user/3/1200/imagename.jpg

$model->image =  $upload->upload( UploadedFile::getInstance($model, 'image'), "users/".Yii::$app->user->id );


rename (Type: boolean, Default value: true)

Will rename your uploaded file, set to false if you don't want to change the file name

remove (Type: boolean, Default value: true)

Remove the original file

baseFrontendUrl ( Type: string)

Your frontend ( or web path for basic template ) path to image folder

baseBackendUrl ( Type: string)

Your backend path to image folder

folders ( Type: array)

The folders are not the primary. - name[] = is the name of the folder - quality[] = is the quality of the uploaded image - width[] = is the width of the image, the height will be scaled

Be the first person to leave a comment

Please to leave your comment.

Create extension
No downloadable files yet