PHPackages                             fredyns/yii2-attachments - 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. fredyns/yii2-attachments

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

fredyns/yii2-attachments
========================

Extension for file uploading and attaching to the models

1.1.1(5y ago)236BSD-4-ClausePHPPHP &gt;=5.4.0

Since Feb 4Pushed 5y ago1 watchersCompare

[ Source](https://github.com/fredyns/yii2-attachments)[ Packagist](https://packagist.org/packages/fredyns/yii2-attachments)[ Docs](https://github.com/fredyns/yii2-attachments)[ RSS](/packages/fredyns-yii2-attachments/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (1)Dependencies (7)Versions (6)Used By (0)

Yii2 Attachments
================

[](#yii2-attachments)

[![Latest Stable Version](https://camo.githubusercontent.com/3cce28a0c3b71252dee6a463dd3618716f4c99ca6e4f49595be920a324a02976/68747470733a2f2f706f7365722e707567782e6f72672f66726564796e732f796969322d6174746163686d656e74732f762f737461626c65)](https://packagist.org/packages/fredyns/yii2-attachments)[![License](https://camo.githubusercontent.com/164ce42a996dd133fb47327eea6f4b2cc65f6d4d6524b48380b6a3798f7cc89e/68747470733a2f2f706f7365722e707567782e6f72672f66726564796e732f796969322d6174746163686d656e74732f6c6963656e7365)](https://packagist.org/packages/fredyns/yii2-attachments)[![Total Downloads](https://camo.githubusercontent.com/5c57b15afe047cc2ac1be412499655ad2d0118cd0eb0cb3d3c4349dbec88b7a9/68747470733a2f2f706f7365722e707567782e6f72672f66726564796e732f796969322d6174746163686d656e74732f646f776e6c6f616473)](https://packagist.org/packages/fredyns/yii2-attachments)

Upload models attachment to Flysystem

Demo
----

[](#demo)

You can see the demo of upload input on the [krajee](http://plugins.krajee.com/file-input/demo) website

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

[](#installation)

1. install [yii2-flysystem](https://github.com/creocoder/yii2-flysystem) and filesystem of your choice.

    Please look closely at its documentation for installation. (it may get some update)
2. The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

    Either run

    ```
    php composer.phar require fredyns/yii2-attachments "dev-master"

    ```

    or add

    ```
    "fredyns/yii2-attachments": "dev-master"

    ```

    to the require section of your `composer.json` file.
3. Add module to `common/config/main.php` (advanced template)

    for basic app you should add to both `config/web.php` &amp; `config/console.php`.

    ```
    'modules' => [
    	...
    	'attachments' => [
    		'class' => fredyns\attachments\Module::class,
    		'rules' => [ // Rules according to the FileValidator
    		    'maxFiles' => 10, // Allow to upload maximum 3 files, default to 3
    			'mimeTypes' => 'image/png', // Only png images
    			'maxSize' => 1024 * 1024 // 1 MB
    		],
    		'tableName' => '{{%attachments}}' // Optional, default to 'attach_file'
    		'filesystem' => 'awss3Fs' // you can change though
    	]
    	...
    ]
    ```
4. Apply migrations

    ```
    	'controllerMap' => [
    	...
    	'migrate' => [
    		'class' => 'yii\console\controllers\MigrateController',
    		'migrationNamespaces' => [
    			'fredyns\attachments\migrations',
    		],
    	],
    	...
    	],
    ```

    ```
    php yii migrate/up

    ```
5. Attach behavior to your model (be sure that your model has "id" property)

    ```
    public function behaviors()
    {
    	return [
    		...
    		'fileBehavior' => [
    			'class' => \fredyns\attachments\behaviors\FileBehavior::class,
    		]
    		...
    	];
    }
    ```
6. Make sure that you have added `'enctype' => 'multipart/form-data'` to the ActiveForm options
7. Make sure that you specified `maxFiles` in module rules and `maxFileCount` on `AttachmentsInput` to the number that you want

Usage
-----

[](#usage)

1. In the `form.php` of your model add file input

    ```

    ```
2. Use widget to show all attachments of the model in the `view.php`

    ```

    ```
3. You can get all attached files by calling `$model->files`, for example:

    ```
    foreach ($model->files as $file) {
        echo $file->path;
    }
    ```

Using Events
------------

[](#using-events)

You may add the following function to your model

```
public function init(){
    $this->on(\fredyns\attachments\behaviors\FileBehavior::EVENT_AFTER_ATTACH_FILES, function ($event) {
        /** @var $files \fredyns\attachments\models\File[] */
        $files = $event->files;
        //your custom code
    });
    parent::init();
}
```

###  Health Score

29

—

LowBetter than 60% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community16

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 51.2% 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 ~623 days

Total

4

Last Release

1881d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/697aad30f5dc5ec23e41b1d5089cee94a64dd71e81979c8c2cd6880a7ec51df3?d=identicon)[fredyns](/maintainers/fredyns)

---

Top Contributors

[![CTOlet](https://avatars.githubusercontent.com/u/5058015?v=4)](https://github.com/CTOlet "CTOlet (43 commits)")[![fredyns](https://avatars.githubusercontent.com/u/4033019?v=4)](https://github.com/fredyns "fredyns (15 commits)")[![drtsb](https://avatars.githubusercontent.com/u/11088965?v=4)](https://github.com/drtsb "drtsb (9 commits)")[![maxxer](https://avatars.githubusercontent.com/u/240201?v=4)](https://github.com/maxxer "maxxer (4 commits)")[![sokollondon](https://avatars.githubusercontent.com/u/11624566?v=4)](https://github.com/sokollondon "sokollondon (2 commits)")[![SAP55](https://avatars.githubusercontent.com/u/3145919?v=4)](https://github.com/SAP55 "SAP55 (2 commits)")[![rapita](https://avatars.githubusercontent.com/u/22305375?v=4)](https://github.com/rapita "rapita (2 commits)")[![marsuboss](https://avatars.githubusercontent.com/u/5856?v=4)](https://github.com/marsuboss "marsuboss (2 commits)")[![zacksleo](https://avatars.githubusercontent.com/u/3369169?v=4)](https://github.com/zacksleo "zacksleo (1 commits)")[![desher](https://avatars.githubusercontent.com/u/794974?v=4)](https://github.com/desher "desher (1 commits)")[![jeffwalsh](https://avatars.githubusercontent.com/u/8369508?v=4)](https://github.com/jeffwalsh "jeffwalsh (1 commits)")[![muhammadcahya](https://avatars.githubusercontent.com/u/4241620?v=4)](https://github.com/muhammadcahya "muhammadcahya (1 commits)")[![abriosi-benassi](https://avatars.githubusercontent.com/u/73604868?v=4)](https://github.com/abriosi-benassi "abriosi-benassi (1 commits)")

---

Tags

digitalocean-spacesflysystems3yii2fileuploadyii2extensionattachment

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/fredyns-yii2-attachments/health.svg)

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

###  Alternatives

[nemmo/yii2-attachments

Extension for file uploading and attaching to the models

6616.6k5](/packages/nemmo-yii2-attachments)[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)
