PHPackages                             icalab/yii2-ica-mediafile - 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. icalab/yii2-ica-mediafile

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

icalab/yii2-ica-mediafile
=========================

Extension for attaching media files to models.

04692PHP

Since Jul 2Pushed 10y ago2 watchersCompare

[ Source](https://github.com/icalab/yii2-ica-mediafile)[ Packagist](https://packagist.org/packages/icalab/yii2-ica-mediafile)[ RSS](/packages/icalab-yii2-ica-mediafile/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (2)Used By (0)

yii2-ica-mediafile
==================

[](#yii2-ica-mediafile)

Extension for attaching media files to models

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

[](#installation)

1. Install the mediafile extension using composer:

```
composer require icalab/yii2-ica-mediafile

```

2. Run the provided migration:

```
php yii migrate --migrationPath=@icalab/mediafile/migrations

```

3. Create a directory mediafiles under the web directory and make it writable for the web server.

Usage
-----

[](#usage)

The relevant code files contain documentation at the top of the files. There is also the Voorbeeld model and the VoorbeeldController that you can use to see an example of how this module works.

In short:

1. Create your model.
2. Attach the ModelWithMediafileBehavior behavior to your model.
3. Create a join table named yourmodel\_mediafile containing a column parentid and a column mediafileid.
4. Attach the behavior ControllerWithMediafileBehavior to your controller. Supply the class name of your model as a parameter (modelClass).
5. Create an action actionUnassign($id, $mediafile) in your controller and make it call the unassignMediafile($id, $mediafile) method that comes from the ControllerWithMediafileBehavior behavior.
6. In your update method, handle uploading of files by adding code like the following:

```
            $model->newFile = UploadedFile::getInstance($model, 'newFile');
            if($model->validate() && (! $model->newFiles || $this->saveMediaFiles($model)))
            {
                $model->save();
                $this->redirect(['update', 'id' => $id]);
            }
```

7. In your form view, show the output of the AttachMediafileWidget widget. Supply the model and the form as a parameter to this widget:

```
echo AttachMediafileWidget::widget(['model' => $model, 'form' => $form]);
```

Notes
-----

[](#notes)

- Uploaded media files can be accessed from the web using the url mediafile/view?id=id\_of\_file
- By default uploaded images are converted to PNG to avoid further loss of quality. This was a requirement for the project we built this module for. If you don't want this, pass an extra parameter FALSE to the saveMediafile method the model inherits from the ModelWithMediafileBehavior behavior.
- The AttachMediafileWidget uses Kartik Visweswaran's excellent FileInput widget:

###  Health Score

25

—

LowBetter than 35% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity43

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 52.8% 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.

### Community

Maintainers

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

---

Top Contributors

[![matthijs-rhmtts](https://avatars.githubusercontent.com/u/195130236?v=4)](https://github.com/matthijs-rhmtts "matthijs-rhmtts (19 commits)")[![mcdejonge](https://avatars.githubusercontent.com/u/7314582?v=4)](https://github.com/mcdejonge "mcdejonge (16 commits)")[![Herjanz](https://avatars.githubusercontent.com/u/3253205?v=4)](https://github.com/Herjanz "Herjanz (1 commits)")

### Embed Badge

![Health badge](/badges/icalab-yii2-ica-mediafile/health.svg)

```
[![Health](https://phpackages.com/badges/icalab-yii2-ica-mediafile/health.svg)](https://phpackages.com/packages/icalab-yii2-ica-mediafile)
```

###  Alternatives

[ericnorris/amazon-s3-php

A lightweight and fast S3 client for PHP.

2147.0k](/packages/ericnorris-amazon-s3-php)

PHPackages © 2026

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