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

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

dlds/yii2-attachments
=====================

Extension for file uploading and attaching to the models

1.1(11y ago)12421[1 PRs](https://github.com/dlds/yii2-attachments/pulls)BSD-4-ClausePHPPHP &gt;=5.4.0

Since Feb 10Pushed 8y ago2 watchersCompare

[ Source](https://github.com/dlds/yii2-attachments)[ Packagist](https://packagist.org/packages/dlds/yii2-attachments)[ RSS](/packages/dlds-yii2-attachments/feed)WikiDiscussions master Synced 1mo ago

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

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

[](#yii2-attachments)

Extension for file uploading and attaching to the models

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

[](#installation)

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

    Either run

    ```
    php composer.phar require dlds/yii2-attachments "*"

    ```

    or add

    ```
    "dlds/yii2-attachments": "*"

    ```

    to the require section of your `composer.json` file.
2. Apply migrations

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

    ```
3. Add module to `config/main.php`

    ```
    'modules' => [
    	...
    	'attachments' => [
    		'class' => dlds\attachments\Module::className(),
    		'tempPath' => '@app/uploads/temp',
    		'storePath' => '@app/uploads/store'
    	]
    	...
    ]
    ```
4. Attach behavior to your model (be sure that your model has "id" property)

    ```
    public function behaviors()
    {
    	return [
    		...
    		'attachmentBehavior' => [
    		'class' => \dlds\attachments\behaviors\AttachmentBehavior::className()
    		]
    		...
    	];
    }
    ```
5. Make sure that you have added `'enctype' => 'multipart/form-data'` to the ActiveForm options

Usage
-----

[](#usage)

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

    ```
