open20/amos-attachments

There is no license information available for the latest version (1.15.1) of this package.

Extension for file uploading and attaching to the models


README

Extension for file uploading and attaching to the models

Demo

You can see the demo on the krajee website

Installation

  1. The preferred way to install this extension is through composer.

Either run

composer require open20/amos-attachments

or add

"open20/amos-attachments": ">=1.0"

to the require section of your composer.json file.

  1. Add module to your main config in common:
<?php
'aliases' => [
    '@file' => dirname(__DIR__),
],
'modules' => [
    'attachments' => [
        'class' => 'open20\amos\attachments\FileModule',
        'webDir' => 'files',
        'tempPath' => '@common/uploads/temp',
        'storePath' => '@common/uploads/store',
        // 'tableName' => '{{%attach_file}}' // Optional, default to 'attach_file'
    ],
],

Also, add these lines to your console config:

<?php
'controllerMap' => [
    'attachments' => [
        'class' => 'yii\console\controllers\MigrateController',
        'migrationPath' => '@amos_attachments/migrations'
    ],
],
  1. Apply migrations
php yii migrate/up --migrationPath=@vendor/open20/amos-attachments/src/migrations
  1. Attach behavior to your model (be sure that your model has "id" property)
<?php
use yii\helpers\ArrayHelper;

/**
 * Adding the file behavior
 */
public function behaviors()
{
    return ArrayHelper::merge(parent::behaviors(), [
        'fileBehavior' => [
            'class' => \file\behaviors\FileBehavior::className()
        ]
    ]);
}

/**
 * Add the new fields to the file behavior
 */
public function rules()
{
    return ArrayHelper::merge(parent::rules(), [
        [['my_field_multiple_files', 'my_field_single_file'], 'file'],
    ]);
}
  1. Make sure that you have added 'enctype' => 'multipart/form-data' to the ActiveForm options

  2. Make sure that you specified maxFiles in module rules and maxFileCount on AttachmentsInput to the number that you want

  3. Youre ready to use, See How