yii2-easy-uploader easy way to upload image

github url

https://github.com/gomonkey/yii2-easy-uploader

Report an issue

https://github.com/gomonkey/yii2-easy-uploader/issues

Description

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

Installation

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.

Usage

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 );
 

Paremeters

  1. github url
  2. Report an issue
  3. Description
  4. Installation
  5. Usage
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
2 0
2 followers
0 downloads
Yii Version: 2.0
License: MIT
Category: File System
Developed by: gabriele
Created on: Oct 2, 2017
Last updated: 7 years ago

Related Extensions