2017 © Pedro PelĂĄez
 

yii2-extension yii2-uploader-behavior

Yii2 Uploader Behavior for Active Record that automates file uploading for every attribute tagged with `file` or `image` validation rule. It also configures the way that filename should be renamed and stored in database as attribute value.

image

daxslab/yii2-uploader-behavior

Yii2 Uploader Behavior for Active Record that automates file uploading for every attribute tagged with `file` or `image` validation rule. It also configures the way that filename should be renamed and stored in database as attribute value.

  • Sunday, March 4, 2018
  • by glpzzz
  • Repository
  • 2 Watchers
  • 0 Stars
  • 81 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 4 Versions
  • 1 % Grown

The README.md

Yii2 Uploader Behavior for Active Record

Build Status Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

Automates file uploading for every attribute tagged with file or image validation rule. It also configures the way that filename should be renamed and stored in database as attribute value., (*2)

Installation

The preferred way to install this extension is through composer., (*3)

Either run, (*4)

php composer.phar require --prefer-dist daxslab/yii2-uploader-behavior "*"

or add, (*5)

"daxslab/yii2-uploader-behavior": "*"

to the require section of your composer.json file., (*6)

Usage

Once the extension is installed, simply use it in your models by :, (*7)

use daxslab/behaviors/UploaderBehavior;

public function behaviors() {
    return [
        UploaderBehavior::className()
    ];
}

This is the simplest way of usage. It will look for all attributes with a file or image validation rule., (*8)

public function rules()
{
    return [
        [['name'], 'required'],
        [['name'], 'string', 'max' => 256],
        [['image'], 'image', 'skipOnEmpty' => true],
    ];
}

And update the form to specify a file input for the image attribute:, (*9)

$form->field($model, 'image')->fileInput();

For a more controlled usage, you can specify which attributes to control using the attributes option as in :, (*10)

use daxslab/behaviors/UploaderBehavior;

public function behaviors() {
    return [
        [
            'class' => UploaderBehavior::className(),
            'attributes' => ['avatar'] // or you can use the string format as in 'attributes' => 'avatar'
        ]
    ];
}

By default the filename of the uploaded file is randomized, but if you want to configure it you can setup the renamer option:, (*11)

use daxslab/behaviors/UploaderBehavior;

public function behaviors() {
    return [
        [
            'class' => UploaderBehavior::className(),
            'attributes' => ['avatar'] // or you can use the string format as in 'attributes' => 'avatar'
            'renamer' => UploaderBehavior::RENAME_MD5 //will encode the filename with md5()
        ]
    ];
}

also you can specify a custom function to rename the filename:, (*12)

use daxslab/behaviors/UploaderBehavior;

public function behaviors() {
    return [
        [
            'class' => UploaderBehavior::className(),
            'attributes' => ['avatar'] // or you can use the string format as in 'attributes' => 'avatar'
            'renamer' => function($name, $owner){
                return strtoupper($name); //will turn the filename into uppercase
            }
        ]
    ];
}

Proudly made by Daxslab., (*13)

The Versions

04/03 2018

dev-master

9999999-dev

Yii2 Uploader Behavior for Active Record that automates file uploading for every attribute tagged with `file` or `image` validation rule. It also configures the way that filename should be renamed and stored in database as attribute value.

  Sources   Download

GPL-2.0

The Requires

 

by Gabriel A. LĂłpez LĂłpez

extension yii2

04/03 2018

1.0.2

1.0.2.0

Yii2 Uploader Behavior for Active Record that automates file uploading for every attribute tagged with `file` or `image` validation rule. It also configures the way that filename should be renamed and stored in database as attribute value.

  Sources   Download

GPL-2.0

The Requires

 

by Gabriel A. LĂłpez LĂłpez

extension yii2

25/02 2018

1.0.1

1.0.1.0

Yii2 Uploader Behavior for Active Record that automates file uploading for every attribute tagged with `file` or `image` validation rule. It also configures the way that filename should be renamed and stored in database as attribute value.

  Sources   Download

GPL-2.0

The Requires

 

by Gabriel A. LĂłpez LĂłpez

extension yii2

10/01 2018

1.0.0

1.0.0.0

Yii2 Uploader Behavior for Active Record

  Sources   Download

GPL-2.0

The Requires

 

by Gabriel A. LĂłpez LĂłpez

extension yii2