PHPackages                             exocet/yii2-upload-file-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. [File &amp; Storage](/categories/file-storage)
4. /
5. exocet/yii2-upload-file-behavior

ActiveYii2-extension[File &amp; Storage](/categories/file-storage)

exocet/yii2-upload-file-behavior
================================

A Yii2 behavior designed to simplify the process of uploading and managing files and images associated with ActiveRecord models.

1.0.0(2y ago)137MITPHP

Since Sep 20Pushed 2y ago1 watchersCompare

[ Source](https://github.com/xchwarze/yii2-upload-file-behavior)[ Packagist](https://packagist.org/packages/exocet/yii2-upload-file-behavior)[ RSS](/packages/exocet-yii2-upload-file-behavior/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (0)

UploadFileBehavior for Yii2
===========================

[](#uploadfilebehavior-for-yii2)

`UploadFileBehavior` is a Yii2 behavior designed to streamline the process of uploading files and/or images. It manages the processing and storage of files associated with an ActiveRecord model.

Features
--------

[](#features)

- File uploading for ActiveRecord models.
- Customizable file saving steps.
- Thumbnail generation.
- Option to rename uploaded files.
- Ability to delete files when associated records are deleted.
- Automatic cleanup of directories during updates.

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

[](#installation)

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

```
composer require "exocet/yii2-upload-file-behavior"
```

Setup and Configuration
-----------------------

[](#setup-and-configuration)

1. Include new behavior:

    ```
    use exocet\yii2UploadFileBehavior\UploadFileBehavior;
    ```
2. Add the upload file attribute to your model:

    ```
    public $upload_file;
    ```
3. Add safety rules for your image path or similar:

    ```
    [['image_path'], 'safe'],
    ```
4. Attach the behavior to your model:

    ```
    public function behaviors() {
        return [
            'uploadFileBehavior' => [
                'class' => UploadFileBehavior::className(),
                'nameOfAttributeStorage' => 'image_path',
                //... other configurations
            ],
        ];
    }
    ```

### Configuration Options

[](#configuration-options)

Here's a quick run-through of the configuration options:

- `modelAttributeForFile`: (string) The model's attribute to receive the file from the form. Defaults to `'upload_file'`.
- `modelAttributeForStorage`: (string) The model's attribute to store the file path or reference. Defaults to `'images'`.
- `newFileName`: (bool|string) A new filename to save the uploaded file as. Defaults to `false` (meaning it won't rename).
- `steps`: (array) Configurations detailing where and how to save the uploaded file. This can include thumbnail generation, different save paths, etc.
- `thumbnailPrefix`: (string) Prefix for generated thumbnails. Defaults to `'thumb-'`.
- `originalPrefix`: (string) Prefix to use when saving a copy of the original image. Defaults to `'original-'`.
- `scenarios`: (array) Scenarios under which this behavior will be triggered. Defaults to `['default']`.
- `deleteImageWithRecord`: (bool) Whether or not to delete the file when the associated record is deleted. Defaults to `false`.
- `cleanDirWithUpdate`: (bool) Whether or not to clean the upload directory when updating files. Defaults to `false`.

For more in-depth examples and how to set up the `steps` configuration, refer to the example given in the code comments.

Contribution
------------

[](#contribution)

Feel free to contribute to this project by opening issues, pull requests, or providing feedback. Your contributions are welcome!

---

Designed with ❤️ for Yii2 developers.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

965d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2bf827fe1f9178509f0c8464ab7dd2dbe066d2c697baaee7ca65576b67128e88?d=identicon)[xchwarze](/maintainers/xchwarze)

---

Top Contributors

[![xchwarze](https://avatars.githubusercontent.com/u/2120205?v=4)](https://github.com/xchwarze "xchwarze (2 commits)")

---

Tags

yii2Behavioryiiuploader

### Embed Badge

![Health badge](/badges/exocet-yii2-upload-file-behavior/health.svg)

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

###  Alternatives

[sjaakp/yii2-illustrated-behavior

ActiveRecord Behavior with associated Widget for Yii2.

423.1k](/packages/sjaakp-yii2-illustrated-behavior)[liyunfang/yii2-upload-behavior

Upload behavior for Yii 2

161.7k](/packages/liyunfang-yii2-upload-behavior)

PHPackages © 2026

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