PHPackages                             daxslab/yii2-uploader-behavior - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. daxslab/yii2-uploader-behavior

ActiveYii2-extension

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.

1.0.3(2y ago)3703↓100%GPL-2.0PHP

Since Jan 9Pushed 2y ago2 watchersCompare

[ Source](https://github.com/daxslab/yii2-uploader-behavior)[ Packagist](https://packagist.org/packages/daxslab/yii2-uploader-behavior)[ RSS](/packages/daxslab-yii2-uploader-behavior/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (4)Dependencies (1)Versions (5)Used By (0)

Yii2 Uploader Behavior for Active Record
========================================

[](#yii2-uploader-behavior-for-active-record)

[![Build Status](https://camo.githubusercontent.com/0d3a9cd6222ffc1a6cebb1f13d32f1ebccbc8745381b70c9c5a41e087a42813f/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f646178736c61622f796969322d75706c6f616465722d6265686176696f722e706e67)](http://travis-ci.org/daxslab/yii2-uploader-behavior)[![Latest Stable Version](https://camo.githubusercontent.com/4c50463f4eb2e5d491b3e0916cc7e65004a236a3b9f21cb4b611da8346bbaeb9/68747470733a2f2f706f7365722e707567782e6f72672f646178736c61622f796969322d75706c6f616465722d6265686176696f722f762f737461626c652e737667)](https://packagist.org/packages/daxslab/yii2-uploader-behavior)[![Total Downloads](https://camo.githubusercontent.com/31c3fa215c7889c8a0f3c2ab2ba3c06d02de44b4c7fcfba13496c1a19fbdded0/68747470733a2f2f706f7365722e707567782e6f72672f646178736c61622f796969322d75706c6f616465722d6265686176696f722f646f776e6c6f616473)](https://packagist.org/packages/daxslab/yii2-uploader-behavior)[![Latest Unstable Version](https://camo.githubusercontent.com/5d093ffef68db0febcd5301eeec11373b5d29748adc94656a8902273c356ba0b/68747470733a2f2f706f7365722e707567782e6f72672f646178736c61622f796969322d75706c6f616465722d6265686176696f722f762f756e737461626c652e737667)](https://packagist.org/packages/daxslab/yii2-uploader-behavior)[![License](https://camo.githubusercontent.com/12393aef039f0a2d475f4a7c05c0f791d62c8f9f5ab67da32fa3f1c2eacbfea7/68747470733a2f2f706f7365722e707567782e6f72672f646178736c61622f796969322d75706c6f616465722d6265686176696f722f6c6963656e73652e737667)](https://packagist.org/packages/daxslab/yii2-uploader-behavior)

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.

Installation
------------

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

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

```

or add

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

```

to the require section of your `composer.json` file.

Usage
-----

[](#usage)

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

```
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.

```
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:

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

For a more controlled usage, you can specify which attributes to control using the `attributes` option as in :

```
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:

```
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:

```
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](http://daxslab.com).

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~669 days

Total

4

Last Release

1038d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/13596248?v=4)[Gabriel Alejandro López López](/maintainers/glpzzz)[@glpzzz](https://github.com/glpzzz)

![](https://www.gravatar.com/avatar/ee680a9e5bd2827f4097e661681a88d64ea64e7c82c22a2398ed0d544676b11a?d=identicon)[cccaballero](/maintainers/cccaballero)

---

Top Contributors

[![glpzzz](https://avatars.githubusercontent.com/u/13596248?v=4)](https://github.com/glpzzz "glpzzz (9 commits)")

---

Tags

yii2extension

### Embed Badge

![Health badge](/badges/daxslab-yii2-uploader-behavior/health.svg)

```
[![Health](https://phpackages.com/badges/daxslab-yii2-uploader-behavior/health.svg)](https://phpackages.com/packages/daxslab-yii2-uploader-behavior)
```

###  Alternatives

[skeeks/cms

SkeekS CMS — control panel and tools based on php framework Yii2

13825.6k47](/packages/skeeks-cms)[dmstr/yii2-cookie-consent

Yii2 Cookie Consent Widget

1452.6k](/packages/dmstr-yii2-cookie-consent)[richardfan1126/yii2-js-register

Yii2 widget to register JS into view

1357.2k7](/packages/richardfan1126-yii2-js-register)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
