PHPackages                             itstructure/yii2-multi-format-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. itstructure/yii2-multi-format-uploader

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

itstructure/yii2-multi-format-uploader
======================================

Module for Yii2 Framework to upload some type of files to local or S3 Amazon storage

3.2.9(6mo ago)53362[1 issues](https://github.com/itstructure/yii2-multi-format-uploader/issues)MITPHPPHP &gt;=7.1.0CI failing

Since May 15Pushed 6mo agoCompare

[ Source](https://github.com/itstructure/yii2-multi-format-uploader)[ Packagist](https://packagist.org/packages/itstructure/yii2-multi-format-uploader)[ RSS](/packages/itstructure-yii2-multi-format-uploader/feed)WikiDiscussions master Synced 6d ago

READMEChangelog (10)Dependencies (5)Versions (28)Used By (0)

Yii2 Multi format uploader module - MFUploader
==============================================

[](#yii2-multi-format-uploader-module---mfuploader)

Introduction
------------

[](#introduction)

[![Latest Stable Version](https://camo.githubusercontent.com/3444701799e191d3bc97d0dd08429dfa68edccacfa269b2e2862a8b794978e29/68747470733a2f2f706f7365722e707567782e6f72672f69747374727563747572652f796969322d6d756c74692d666f726d61742d75706c6f616465722f762f737461626c65)](https://packagist.org/packages/itstructure/yii2-multi-format-uploader)[![Latest Unstable Version](https://camo.githubusercontent.com/ce682aba194947d4ef309c9b1f6af8be0bdf38637730a50053cc3e50de3b9987/68747470733a2f2f706f7365722e707567782e6f72672f69747374727563747572652f796969322d6d756c74692d666f726d61742d75706c6f616465722f762f756e737461626c65)](https://packagist.org/packages/itstructure/yii2-multi-format-uploader)[![License](https://camo.githubusercontent.com/7e8f52e1043d1845c84337171e9d29f4cf7ce3566bc29b6230a524e14dbbbd64/68747470733a2f2f706f7365722e707567782e6f72672f69747374727563747572652f796969322d6d756c74692d666f726d61742d75706c6f616465722f6c6963656e7365)](https://packagist.org/packages/itstructure/yii2-multi-format-uploader)[![Total Downloads](https://camo.githubusercontent.com/503f3be5aff0efecde2d674e87d5e914ef7b5be1e13164cb5423db8ee5801809/68747470733a2f2f706f7365722e707567782e6f72672f69747374727563747572652f796969322d6d756c74692d666f726d61742d75706c6f616465722f646f776e6c6f616473)](https://packagist.org/packages/itstructure/yii2-multi-format-uploader)[![Build Status](https://camo.githubusercontent.com/1039237b86f809e3801c5827b675c07f8d64a66b58c62be312f38156c71bd6df/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f69747374727563747572652f796969322d6d756c74692d666f726d61742d75706c6f616465722f6261646765732f6275696c642e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/itstructure/yii2-multi-format-uploader/build-status/master)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/7a0e5e9ef6c474bc1f3379635c42dd4c7cd706d9387c5804f6224efa2460f334/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f69747374727563747572652f796969322d6d756c74692d666f726d61742d75706c6f616465722f6261646765732f7175616c6974792d73636f72652e706e673f623d6d6173746572)](https://scrutinizer-ci.com/g/itstructure/yii2-multi-format-uploader/?branch=master)

**MFUploader** -- Module for the Yii2 v2.0.x Framework to upload some type of files to local or S3 Amazon storage. MFUploader module provides the following options:

- Upload files to local storage.
- Upload files to remote Amazon S3 storage.
- Support file formats: **image**, **audio**, **video**, **application**, **text**.
- Link uploaded files with external application owners (pages, articles, posts e.t.c...).
- Manage internal albums: **imageAlbum**, **audioAlbum**, **videoAlbum**, **applicationAlbum**, **textAlbum**, **otherAlbum**.
- Link uploaded files with internal albums (owners).
- Link internal albums with the external owners (pages, articles, posts e.t.c...).

To work with image binary content it uses [Yii2 imagine](https://github.com/yiisoft/yii2-imagine). To work with Amazon it uses [AWS SDK](https://github.com/aws/aws-sdk-php).

Base project examples, which use this MFUploader module:

[yii2-template-multilanguage](https://github.com/itstructure/yii2-template-multilanguage).

[yii2-template-simple](https://github.com/itstructure/yii2-template-simple).

Addition module description you can see in my [Personal site](https://pack-develop.info/en/product/yii2-multi-format-uploader).

Requirements
------------

[](#requirements)

- php &gt;= 7.1
- composer 2
- MySql &gt;= 5.5 or MariaDB &gt;= 10.1
- One of the next php extensions: GD|Imagick|Gmagick

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

[](#installation)

### Base install

[](#base-install)

Via composer:

`composer require itstructure/yii2-multi-format-uploader ~3.2.9`

### If you are testing this package from local server directory

[](#if-you-are-testing-this-package-from-local-server-directory)

In application `composer.json` file set the repository, like in example:

```
"repositories": [
    {
        "type": "path",
        "url": "../yii2-multi-format-uploader",
        "options": {
            "symlink": true
        }
    }
],
```

Here,

**yii2-multi-format-uploader** - directory name, which has the same directory level like application and contains yii2 multi format uploader package.

Then run command:

`composer require itstructure/yii2-multi-format-uploader:dev-master --prefer-source`

### Apply module migrations

[](#apply-module-migrations)

For that make next, **if not already done**:

- Define **mfuploader** module in application **console** config file:

    ```
    use Itstructure\MFUploader\Module as MFUModule;
    ```

    ```
    'modules' => [
        'mfuploader' => [
            'class' => MFUModule::class,
        ],
    ],
    ```
- In file **yii**, that is located in application root directory, set **@mfuploader** alias:

    ```
    $application = new yii\console\Application($config);

    \Yii::setAlias('@mfuploader', $application->getModule('mfuploader')->getBasePath());

    $exitCode = $application->run();
    ```

    OR

    ```
    use Itstructure\MFUploader\Module as MFUModule;
    ```

    ```
    $application = new yii\console\Application($config);

    \Yii::setAlias('@mfuploader', MFUModule::getBaseDir());

    $exitCode = $application->run();
    ```
- Run command in console:

    `yii migrate --migrationPath=@mfuploader/migrations`

    The data base structure:

    [![Data base structure](https://github.com/itstructure/yii2-multi-format-uploader/raw/master/db_structure.jpg)](https://github.com/itstructure/yii2-multi-format-uploader/blob/master/db_structure.jpg)

Usage
-----

[](#usage)

### Main properties

[](#main-properties)

The **name** of module: `mfuploader`

The **namespace** for used classes: `Itstructure\MFUploader`.

The **alias** to access in to module root directory: `@mfuploader`.

### Application config

[](#application-config)

Base application config must be like in example below:

```
use Itstructure\MFUploader\Module as MFUModule;
use Itstructure\MFUploader\controllers\ManagerController;
use Itstructure\MFUploader\controllers\upload\{
    LocalUploadController,
    S3UploadController
};
use Itstructure\MFUploader\controllers\album\{
    ImageAlbumController,
    AudioAlbumController,
    VideoAlbumController,
    ApplicationAlbumController,
    TextAlbumController,
    OtherAlbumController
};
use Itstructure\MFUploader\components\{
    LocalUploadComponent,
    S3UploadComponent
};
```

```
'modules' => [
    'mfuploader' => [
        'class' => MFUModule::class, // REQUIRED
        'layout' => ...path to layout..., // NOT REQUIRED
        'view' => ...view component config..., // NOT REQUIRED
        'controllerMap' => [ // CUSTOM
            'upload/local-upload' => LocalUploadController::class,
            'upload/s3-upload' => S3UploadController::class,
            'managers' => ManagerController::class,
            'image-album' => ImageAlbumController::class,
            'audio-album' => AudioAlbumController::class,
            'video-album' => VideoAlbumController::class,
            'application-album' => ApplicationAlbumController::class,
            'text-album' => TextAlbumController::class,
            'other-album' => OtherAlbumController::class,
        ],
        'accessRoles' => ['admin', 'manager', e.t.c...], // CUSTOM
        'defaultStorageType' => MFUModule::STORAGE_TYPE_S3, // CUSTOM
        'components' => [ // CUSTOM
            'local-upload-component' => [ // CUSTOM
                'class' => LocalUploadComponent::class,
                'checkExtensionByMimeType' => false,
                'uploadRoot' => dirname($_SERVER['SCRIPT_FILENAME'])
            ],
            's3-upload-component' => [ // CUSTOM
                'class' => S3UploadComponent::class,
                'checkExtensionByMimeType' => false,
                'credentials' => require __DIR__ . '/aws-credentials.php',
                'region' => 'us-west-2',
                's3DefaultBucket' => 'bucketname',
            ],
        ],
        'publicBaseUrl' => 'http://your-site-address.com'
    ],
],
```

Here `publicBaseUrl` for example can be a project domain (`http://your-site-address.com`). If we have `url` in `mediafiles` table `\uploads\images\imagealbum\0d\3890\a947f268d6f9fd02d8a0d7e147da922c.jpg`, and we use **getViewUrl()** function from a `mediafile` model for local files, then for example a result link to image for `src` attribute of `` tag will be:

`http://your-site-address.com/uploads/images/imagealbum/0d/3890/a947f268d6f9fd02d8a0d7e147da922c.jpg`

**Note:** It is not necessary to configure two components: `local-upload-component` and `s3-upload-component`. You must configure minimum one component, according with the `defaultStorageType`.

### File field for the view template

[](#file-field-for-the-view-template)

**File field** must be rendered by `FileSetter` widget.

It is necessary to send an ID or URL of uploaded mediafile to you application controller and set in model. An after that to link mediafile ID with owner.

Example (for image files):

```
use Itstructure\MFUploader\widgets\FileSetter;
use Itstructure\MFUploader\Module as MFUModule;
use Itstructure\MFUploader\interfaces\UploadModelInterface;
```

```
Container to display selected image.

```

```
echo FileSetter::widget([
    'model' => $model,
    'attribute' => UploadModelInterface::FILE_TYPE_IMAGE,
    'neededFileType' => UploadModelInterface::FILE_TYPE_IMAGE,
    'buttonName' => MFUModule::t('main', 'Set image'),
    'options' => [
        'id' => Html::getInputId($model, UploadModelInterface::FILE_TYPE_IMAGE)
    ],
    'mediafileContainer' => '#mediafile-container',
    'titleContainer' => '#title-container',
    'descriptionContainer' => '#description-container',
    'owner' => 'post', // can be page, article, catalog e.t.c...
    'ownerId' => {current owner id, post id, page id e.t.c.},
    'ownerAttribute' => UploadModelInterface::FILE_TYPE_IMAGE,
    'subDir' => 'post' // can be page, article, catalog e.t.c...
]);
```

### Configure upload components

[](#configure-upload-components)

#### Base attributes in BaseUploadComponent

[](#base-attributes-in-baseuploadcomponent)

**Note:** BaseUploadComponent - the base class, which LocalUploadComponent and S3UploadComponent extend.

To understand the principles of configure the base attributes, see public attributes in `components\BaseUploadComponent` class. But it may be difficult to configure `thumbsConfig` and `thumbFilenameTemplate`. Attribute `thumbsConfig` takes the values according with the next chain:

1. From the default config file `config/thumbs-config.php` in module **init()** function.
2. Can be rewrited by custom during module `thumbsConfig` attribute.
3. Previous config result inserted in to the `LocalUploadComponent` and `S3UploadComponent` module components.
4. Configuration `thumbsConfig` in module components can be rewrited by custom during component `thumbsConfig` attribute.

#### Attributes in LocalUploadComponent

[](#attributes-in-localuploadcomponent)

That is very simple. See public attributes in `components\LocalUploadComponent` class.

#### Attributes in S3UploadComponent

[](#attributes-in-s3uploadcomponent)

See public attributes in `components\S3UploadComponent` class. But there are important attributes:

- `credentials`. Attribute to access in to Amazon web services account. Can be: array, callable, and other. See .
- `s3DefaultBucket` - bucket, which you use to upload files as default.
- `s3Buckets` - buckets to upload files depending on the owner. Not required.

    config example:

    ```
    's3Buckets' => [
      'post' => 'bucketWithPosts',
      'page' => 'bucketWithPages',
      'imageAlbum' => 'bucketWithImages',
      'audioAlbum' => 'bucketWithAudio',
    ]
    ```

For more information of S3 configuration, see the next links:

-
-
-

### Link entities with owners

[](#link-entities-with-owners)

To link entities (mediafiles and albums) with owners (pages, articles, posts e.t.c...) there is the abstract class `behaviors\Behavior`.

You must use child classes: `behaviors\BehaviorMediafile` and `behaviors\BehaviorAlbum`.

Explanation by example.

You have a `catalog` model which extends an ActiveRecord yii2 class.

Use a `behaviors\BehaviorMediafile` and `behaviors\BehaviorAlbum` in **behaviors** of your `catalog` model to link mediafiles and albums with catalog after: **insert active record**, **update active record**, **delete active record**:

```
use Itstructure\MFUploader\behaviors\{BehaviorMediafile, BehaviorAlbum};
use Itstructure\MFUploader\interfaces\UploadModelInterface;
use Itstructure\MFUploader\models\album\Album;
```

```
public $thumbnail;

public $imageAlbum = [];

public function behaviors()
{
    return ArrayHelper::merge(parent::behaviors(), [
        'mediafile' => [
            'class' => BehaviorMediafile::class,
            'name' => static::tableName(),
            'attributes' => [
                UploadModelInterface::FILE_TYPE_THUMB,
            ],
        ],
        'albums' => [
            'class' => BehaviorAlbum::class,
            'name' => static::tableName(),
            'attributes' => [
                Album::ALBUM_TYPE_IMAGE,
            ],
        ],
    ]);
}
```

**Note:** This block should be used in conjunction with the `FileSetter` widget inside the view form template!

Here the following happens:

- If you use a "thumbnail" name of `attribute` param in FileSetter widget, the uploaded mediafile (thumbnail) will be linked with `catalog` after insert new catalog data to the data base.
- If you use an "imageAlbum" (by Album::ALBUM\_TYPE\_IMAGE) name of the `name` attribute of dropdown or checkbox html field, the last created image album will be linked with `catalog` after insert new catalog data to the data base.

That works according with the next data base example structure:

`Table "mediafiles"` - record with id=20 now inserted.

```
| id  | ... |      created_at     |      updated_at     |
|-----|-----|---------------------|---------------------|
| ... | ... |         ...         |         ...         |
| 20  | ... | 2018-05-06 21:35:04 | 2018-05-06 21:35:10 |

```

`Table "catalog"` - record with id=10 inserted after create mediafile (id=20).

```
| id  | ... |      created_at     |      updated_at     |
|-----|-----|---------------------|---------------------|
| ... | ... |         ...         |         ...         |
| 10  | ... | 2018-05-06 21:35:20 | 2018-05-06 21:35:25 |

```

`Table "owners_mediafiles"`

```
| mediafileId | ownerId |   owner   |  ownerAttribute  |
|-------------|---------|-----------|------------------|
|     ...     |   ...   |    ...    |        ...       |
|     20      |    10   |  catalog  |     thumbnail    |

```

`Table "albums"`

```
| id  |     type    | ... |      created_at     |      updated_at     |
|-----|-------------|-----|---------------------|---------------------|
| ... |     ...     | ... |         ...         |         ...         |
|  5  | imageAlbum  | ... | 2018-05-06 21:30:00 | 2018-05-06 21:30:05 |

```

`Table "owners_albums"`

```
| albumId | ownerId |   owner   |  ownerAttribute  |
|---------|---------|-----------|------------------|
|   ...   |   ...   |    ...    |        ...       |
|    5    |    10   |  catalog  |    imageAlbum    |

```

**Note:** If you set in `FileSetter` widget the attributes: `owner`, `ownerId`, `ownerAttribute` - linking entity with owner will be done automatically during ajax request in **uploadmanager**.

### Integrated album controllers

[](#integrated-album-controllers)

There are already integrated album controllers in the namespace: `Itstructure\MFUploader\controllers\album`. Controllers provide the work with the next types of albums: **imageAlbum**, **audioAlbum**, **videoAlbum**, **applicationAlbum**, **textAlbum**, **otherAlbum**.

For that controllers there are already the models and view templates.

To work with that, you must set just the routes in application configuration.

License
-------

[](#license)

Copyright © 2018-2025 Andrey Girnik .

Licensed under the [MIT license](http://opensource.org/licenses/MIT). See LICENSE.txt for details.

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance61

Regular maintenance activity

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity68

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 ~104 days

Recently: every ~251 days

Total

27

Last Release

209d ago

Major Versions

1.0.0 → 2.0.02018-08-09

2.2.2 → 3.0.02020-07-15

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/31563329?v=4)[Andrey Girnik](/maintainers/itstructure)[@itstructure](https://github.com/itstructure)

---

Top Contributors

[![itstructure](https://avatars.githubusercontent.com/u/31563329?v=4)](https://github.com/itstructure "itstructure (31 commits)")

---

Tags

amazonfileinternal-albumsmodules3-amazon-storageuploadyii2yii2-frameworkyii2-templateamazonfilelocaluploadyii2moduleyii 2

### Embed Badge

![Health badge](/badges/itstructure-yii2-multi-format-uploader/health.svg)

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

###  Alternatives

[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)
