wardany/uploader

uploader behavior based on mohorev/yii2-upload-behavior

Installs: 48

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:yii2-extension

dev-master 2016-10-17 12:38 UTC

This package is not auto-updated.

Last update: 2025-04-02 22:14:39 UTC


README

uploader behavior based on mohorev/yii2-upload-behavior

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist wardany/uploader "*"

or add

"wardany/uploader": "*"

to the require section of your composer.json file.

Usage

Once the extension is installed, simply use it in your code by :

function behaviors()
    {
        $baseurl = isset(Yii::$app->components['frontend']) ? Yii::$app->urlManagerFrontEnd->baseUrl : Yii::$app->urlManager->baseUrl ;
        return [
            [
                'class' => UploadImageBehavior::className(),
                'attribute' => 'image',
                'scenarios' => ['insert', 'update'],
                'path' => '@frontend/web/media/images/{id}',
                'url' => "$baseurl/media/images/{id}",                
                'unlinkOnDelete'=>true,
                'thumbPath' => '@frontend/web/media/images/{id}/thumbnail',
                'thumbUrl' => "$baseurl/media/images/{id}/thumbnail",
                'thumbs' => [
                    'header' => ['width' => 1536, 'height' => 600, 'mode'=>ImageInterface::THUMBNAIL_OUTBOUND],
                    'thumb' => ['width' => 300, 'height' => 300, 'mode'=>ImageInterface::THUMBNAIL_OUTBOUND],
                    'preview' => ['width' => 100, 'height' => 100, 'mode'=>ImageInterface::THUMBNAIL_OUTBOUND],
               ],
            ],
        ];
    }```