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

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

axelpal/yii2-attachments
========================

Extension for file uploading and attaching to the models

v1.0.1(10y ago)07103[1 PRs](https://github.com/AxelPAL/yii2-attachments/pulls)BSD-4-ClausePHPPHP &gt;=5.4.0

Since Nov 16Pushed 8y ago1 watchersCompare

[ Source](https://github.com/AxelPAL/yii2-attachments)[ Packagist](https://packagist.org/packages/axelpal/yii2-attachments)[ RSS](/packages/axelpal-yii2-attachments/feed)WikiDiscussions master Synced 4w ago

READMEChangelog (2)Dependencies (4)Versions (3)Used By (0)

Yii2 attachments
================

[](#yii2-attachments)

Extension for file uploading and attaching to the models

This fork has been made by me and by company Elitmaster.

Demo
----

[](#demo)

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

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

[](#installation)

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

    Either run

    ```
    composer require axelpal/yii2-attachments "dev-master"

    ```

    or add

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

    ```

    to the require section of your `composer.json` file.
2. Add module to your main config:

    ```
    'aliases' => [
            '@file' => dirname(__DIR__),
        ],
        'modules' => [
            'file' => [
                'class' => 'file\FileModule',
                'webDir' => 'files',
                'tempPath' => '@common/uploads/temp',
                'storePath' => '@common/uploads/store',
                'rules' => [ // Правила для FileValidator
                    'maxFiles' => 20,
                    'maxSize' => 1024 * 1024 * 20 // 20 MB
                ],
            ],
        ],
    ```

    Also, add these lines to your console config:

    ```
    'controllerMap' => [
            'file' => [
                'class' => 'yii\console\controllers\MigrateController',
                'migrationPath' => '@file/migrations'
            ],
        ],
    ```
3. Apply migrations

    ```
    php yii migrate/up --migrationPath=@vendor/axelpal/yii2-attachments/migrations

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

    ```
    public function behaviors()
    {
    	return [
    		...
    		'fileBehavior' => [
    			'class' => \file\behaviors\FileBehavior::className()
    		]
    		...
    	];
    }
    ```
5. Make sure that you have added `'enctype' => 'multipart/form-data'` to the ActiveForm options
6. 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. (Deprecated) Add onclick action to your submit button that uploads all files before submitting form

    ```
