PHPackages                             sergmoro1/yii2-uploader - 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. sergmoro1/yii2-uploader

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

sergmoro1/yii2-uploader
=======================

File uploader. Upload multiple files at once. Fast Resize and Crop images in a queue. Any size available. Sorting by mouse. Control the max number of uploaded files. File description. Easy setup, quick start.

v2.0.7(5y ago)0961MITPHPPHP &gt;=5.4.0

Since Sep 2Pushed 5y agoCompare

[ Source](https://github.com/sergmoro1/yii2-uploader)[ Packagist](https://packagist.org/packages/sergmoro1/yii2-uploader)[ RSS](/packages/sergmoro1-yii2-uploader/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (6)Versions (11)Used By (1)

Yii2 module for image|file upload
=================================

[](#yii2-module-for-imagefile-upload)

Multiple uploading, sorting file collection by mouse, adding description for the file, cropping. Resize images using the queue component.

Demo
----

[](#demo)

Photos [by categories](http://sample.vorst.ru/photo/index), photo gallery [BEFORE | AFTER](http://sample.vorst.ru/stout/index).

Advantages
----------

[](#advantages)

A common approach for working with uploading images or files in an application.

If the model needs images or files, it is enough:

- to connect the behavior,
- define the subdirectory in which they will be stored,
- define the desired image sizes

For example `common\models\User.php`

```
use sergmoro1\uploader\behaviors\HaveFileBehavior;

class User extends ActiveRecord
{
    /**
     * @inheritdoc
     */
    public function behaviors()
    {
        return array_merge(parent::behaviors(), [
            [
                'class' => HaveFileBehavior::className(),
                'file_path' => '/user/',
                //'check_wh' => false, // not checking min width and height of image
                'sizes' => [
                    //'original' => ['width' => 0, 'height' => 0, 'catalog' => 'original'], // zero values mean not resize
                    'original' => ['width' => 1200, 'height' => 1200, 'catalog' => 'original'],
                    'main'     => ['width' => 400,  'height' => 400,  'catalog' => ''],
                    'thumb'    => ['width' => 90,   'height' => 90,   'catalog' => 'thumb'],
                ],
            ],
        ]);
    }
}
```

Directories
-----------

[](#directories)

Information about all uploaded files are stored in one table `onefile`. There is no need to define a field of type `file` in the model, which need files.

The files are uploaded and stored in the directory defined as a concatenation of paths of three aliases @absolute, @host and @uploader. All aleases should be defined in appropriate config file. For example in `common/config/main-local.php`if storage folder are the same for `backend` and `fronend`.

```
return [
    'aliases' => [
        '@absolute' => '/home/my/site',
        '@host'     => 'http://example.ru',
        '@uploader' => '/uploads',
    ],
```

But there may be different configurations.

If both the backend and frontend are on the same host, the @host alias can be leaved empty. The same case for [basic Yii template](https://github.com/yiisoft/yii2-app-basic).

In the folder the files are arranged by users and sizes.

- `/uploads/user/2`
- `/uploads/user/2/thumb`
- `/uploads/user/2/original`

Where `2` is the user ID or `subdir`. `subdir` can be blank, then all files will be saved in one folder. `subdir` can be defined when widget placed in a view.

Sizes in an example are `thumb`, `main`, `original`. More sizes can be defined but those are `must have`.

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

[](#installation)

The preferred way to install this extension is through composer.

Either run

`composer require --prefer-dist sergmoro1/yii2-uploader`

or add

`"sergmoro1/yii2-uploader": "^2.0.0"`

to the require section of your composer.json.

Run migration.

`php yii migrate --migrationPath=@vendor/sergmoro1/yii2-uploader/src/migrations`

If you used a previous version `sergmoro1\yii2-byone-uploader` then run only the next migration.

`php yii migrate --migrationPath=@vendor/sergmoro1/yii2-uploader/src/migrations/v1`

Configuration
-------------

[](#configuration)

To register the module in an app `common/config/main.php` (advanced) or in appropriate config file.

```
    'modules' => [
        'uploader' => [
            'class' => 'sergmoro1\uploader\Module',
        ],
```

For file storage configuration in `common/config/main-local.php` or any other config file add lines appropriate for your app.

```
return [
    'aliases' => [
        '@absolute' => '/home/my/site',
        '@host'     => '',
        '@uploader' => '/uploads',
    ],
```

If [queue](https://www.yiiframework.com/extension/yiisoft/yii2-queue/doc/guide/2.0/ru/usage) should be using for image resizing, then `queue` component must be defined. The name of the queue component must be exactly `queue`.

Usage
-----

[](#usage)

```
$model = User::findOne(2);

// get top thumb image of the model with image description
echo Html::img($model->getImage('thumb'), ['alt' => $model->getFileDescription()) ]);

// get top image of the model from main catalog
echo Html::img($model->getImage());

// get all images of the model from original catalog with image description
$image = $model->getImage('original');
while ($image) {
    echo Html::img($image, ['title' => $model->getFileDescription()]);
    $image = $model->getNextImage('original');
}
```

To do uploading place the widget in a `_form.php` or any other view.

```

```

If image should be cropped, subdirectories `original`, `main`, `thumb` must to be defined.

May be uploaded any amount of files for one model but files amount can be limited by `limit` parameter of the widget.

If `subdir` will be defined as an empty string then all files will be uploaded in the same folder but with subfolders that was defined in `sizes`.

```

```

Description of uploaded files
-----------------------------

[](#description-of-uploaded-files)

You can leave descriptions to the files. To do this in the `_form.php`, in the already mentioned widget, you need to add the parameter `appendeixView`.

```

```

And add to the view`/views/user/appendix.php` the following content:

```

    vars->description) ? $file->vars->description : ''; ?>

```

Field `description` defined by default, but fields not limited.

Widget options
--------------

[](#widget-options)

**cropAllowed** (`false`)

If image should be cropped, `original`, `main`, `thumb` sizes must be defined.

The cropping sizes are specified by the main directory where `catalor` parameter should be equal `''`.

If this directory is set to square, then the remaining sizes will be square after cropping.

**draggable** (`false`)

Make `true` if uploaded files should be swapped.

**allowedTypes** ( `[]` )

To control files types on a client side, `['image/pjpeg', 'image/jpeg', 'image/png', 'image/x-png', 'image/gif', 'image/x-gif']`. Any if empty.

**allowedTypesReg** ( `'/image\\/[jpeg|jpg|png|gif]/i'` )

Server side control. Any if empty. Preferable way to check allowed types to upload.

**appendixView** ( `''` )

View file name of additional fields for uploaded files. See [views/user/appendix.php](https://github.com/sergmoro1/yii2-user/blob/master/src/views/user/appendix.php).

**minFileSize** ( `0` )

Minimum file size in bytes. `0` for any.

**maxFileSize** ( `0` )

Maximum file size in bytes. `0` for any.

**limit** ( `0` )

Maximum amount of files to upload for one model. `0` for any.

**secure** ( `true` )

Ordinary user authorization required, but verification may be switched off.

**subdir** ( `null` )

If `null` (by defauld) `$model->id` will be used.

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity59

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

Every ~31 days

Recently: every ~11 days

Total

10

Last Release

2168d ago

Major Versions

v1.1.1 → v2.0.02020-04-06

### Community

Maintainers

![](https://www.gravatar.com/avatar/47754c3aa326cd8f607f8207a47193bb3286eac44fded6dd5a312da13358e76c?d=identicon)[sergmoro1](/maintainers/sergmoro1)

---

Top Contributors

[![sergmoro1](https://avatars.githubusercontent.com/u/5292104?v=4)](https://github.com/sergmoro1 "sergmoro1 (113 commits)")

---

Tags

imageresizefileuploadyii2descriptionthumbcropmultiplesorting

### Embed Badge

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

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

###  Alternatives

[mohorev/yii2-upload-behavior

Upload behavior for Yii 2

128265.5k9](/packages/mohorev-yii2-upload-behavior)[yii-dream-team/yii2-upload-behavior

Yii2 file/image upload behavior for ActiveRecord

79207.1k16](/packages/yii-dream-team-yii2-upload-behavior)[liyunfang/yii2-upload-behavior

Upload behavior for Yii 2

161.7k](/packages/liyunfang-yii2-upload-behavior)[karpoff/yii2-crop-image-upload

Yii 2 Crop image upload widget

1818.5k](/packages/karpoff-yii2-crop-image-upload)[sadovojav/yii2-image-cutter

Yii2 crop image widget

108.6k](/packages/sadovojav-yii2-image-cutter)

PHPackages © 2026

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