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

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

mazpaijo/yii2-attachments-aws
=============================

Extension for file uploading and attaching to the models

1161[2 PRs](https://github.com/mazpaijo/yii2-attachments-aws/pulls)PHPCI failing

Since Nov 29Pushed 6y ago1 watchersCompare

[ Source](https://github.com/mazpaijo/yii2-attachments-aws)[ Packagist](https://packagist.org/packages/mazpaijo/yii2-attachments-aws)[ RSS](/packages/mazpaijo-yii2-attachments-aws/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependenciesVersions (1)Used By (0)

Yii2 attachments-aws
====================

[](#yii2-attachments-aws)

[![Latest Stable Version](https://camo.githubusercontent.com/51e88dc23c91a4aeced32ae8005ecbab39d12b29eb2cab20b387c7cc2d61df39/68747470733a2f2f706f7365722e707567782e6f72672f6d617a7061696a6f2f796969322d6174746163686d656e74732d6177732f762f737461626c65)](https://packagist.org/packages/mazpaijo/yii2-attachments-aws)[![License](https://camo.githubusercontent.com/1676474cce8a027ac54a5325f12301607208ee38138382fd4b1cde3e65951389/68747470733a2f2f706f7365722e707567782e6f72672f6d617a7061696a6f2f796969322d6174746163686d656e74732d6177732f6c6963656e7365)](https://packagist.org/packages/mazpaijo/yii2-attachments-aws)[![Build Status](https://camo.githubusercontent.com/d73af8986f203614347043db3a58d4ec6674f3fd991163c9063453444df9038c/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d617a7061696a6f2f796969322d6174746163686d656e74732d6177732f6261646765732f6275696c642e706e673f623d7465737473)](https://scrutinizer-ci.com/g/mazpaijo/yii2-attachments-aws/build-status/tests)[![Code Coverage](https://camo.githubusercontent.com/27f777744049c80553de623336f7610a1a48061e25f8b7c59a71359fcfa6dd8b/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d617a7061696a6f2f796969322d6174746163686d656e74732d6177732f6261646765732f636f7665726167652e706e673f623d7465737473)](https://scrutinizer-ci.com/g/mazpaijo/yii2-attachments-aws/?branch=tests)[![Scrutinizer Code Quality](https://camo.githubusercontent.com/16d408f01072f6dead1ab1958f051aaf40a59d7f1acf0031054840f94b5b5517/68747470733a2f2f7363727574696e697a65722d63692e636f6d2f672f6d617a7061696a6f2f796969322d6174746163686d656e74732d6177732f6261646765732f7175616c6974792d73636f72652e706e673f623d7465737473)](https://scrutinizer-ci.com/g/mazpaijo/yii2-attachments-aws/?branch=tests)[![Total Downloads](https://camo.githubusercontent.com/21947e82b62dc1b69765e5eba43f280cd415e563780cd07ad140d00133a68d4a/68747470733a2f2f706f7365722e707567782e6f72672f6d617a7061696a6f2f796969322d6174746163686d656e74732d6177732f646f776e6c6f616473)](https://packagist.org/packages/mazpaijo/yii2-attachments-aws)

Extension for file uploading and attaching to the models

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

    ```
    php composer.phar require mazpaijo/yii2-attachments-aws "~1.0.0"

    ```

    or add

    ```
    "mazpaijo/yii2-attachments-aws": "~1.0.0"

    ```

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

    ```
    'modules' => [
    	...
    	'attachments-aws' => [
    		'class' => mazpaijo\attachmentsAws\Module::className(),
    		'tempPath' => '@app/uploads/temp',
    		'storePath' => '@app/uploads/store',
    		'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-aws}}' // Optional, default to 'attach_file'
    	]
    	...
    ]
    ```
3. Apply migrations

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

    ```
    php yii migrate/up

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

    ```
    public function behaviors()
    {
    	return [
    		...
    		'fileBehavior' => [
    			'class' => \mazpaijo\attachmentsAws\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-aws of the model in the `view.php`

    ```

    ```
3. (Deprecated) Add onclick action to your submit button that uploads all files before submitting form

    ```
