Skip to content

skylark26/yii2-image-upload-behavior

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 

Repository files navigation

yii2-image-upload-behavior

Behavior for upload photos.

Features:

  • Upload multiple images
  • Resize images
  • Create thumbnails

Dependencies

yii2-imagine

Using:

Put ImageUploadBehavior.php in common\components

Code in the model

use common\components\ImageUploadBehavior;

public function behaviors()
{
    return [
        [
            'class' => ImageUploadBehavior::className(),
            'attributes' => [
                [
                    'instanceAttribute' => 'imagePhoto', //form field attribute
                    'attribute' => 'image', //model attribute
                    'filePath' => $this->getImagesPath(), //path to image
                    'resize' => ['width' => 159], //resize image
                    'createThumb' => false,
                ],
                [
                    'instanceAttribute' => 'preview', //form field attribute
                    'attribute' => 'cover_image', //model attribute
                    'filePath' => $this->getCoverImagePath(), //path to image
                    'resize' => ['height' => 100], //resize image
                    'createThumb' => false,
                ],
            ],
        ],
    ];
}

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages