arter / amos-attachments
There is no license information available for the latest version (1.6.0) of this package.
Extension for file uploading and attaching to the models
1.6.0
2024-04-03 08:50 UTC
Requires
- php: >=5.4.0
- arter/amos-core: ^1.17.0
- bower-asset/jquery-cropper: ^1.0
- himiklab/yii2-colorbox-widget: *
- kartik-v/yii2-widget-fileinput: 1.0.6
- ralouphie/mimey: ^2.1.0
- uitrick/yii2-widget-upload-crop: ^1.0.0
- yiisoft/yii2: ^2.0.0
- yiisoft/yii2-imagine: ^2.1.0
- yiisoft/yii2-jui: ^2.0
- yurkinx/yii2-image: *
Requires (Dev)
- phpunit/dbunit: ~1.0
- phpunit/phpunit: ~4.0
This package is auto-updated.
Last update: 2025-03-07 11:03:26 UTC
README
Extension for file uploading and attaching to the models
Demo
You can see the demo on the krajee website
Installation
- The preferred way to install this extension is through composer.
Either run
composer require arter/amos-attachments
or add
"arter/amos-attachments": ">=1.0"
to the require section of your composer.json
file.
- Add module to your main config in common:
<?php
'aliases' => [
'@file' => dirname(__DIR__),
],
'modules' => [
'attachments' => [
'class' => 'arter\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'
],
],
- Apply migrations
php yii migrate/up --migrationPath=@vendor/arter/amos-attachments/src/migrations
- 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'],
]);
}
Make sure that you have added
'enctype' => 'multipart/form-data'
to the ActiveForm optionsMake sure that you specified
maxFiles
in module rules andmaxFileCount
onAttachmentsInput
to the number that you wantYoure ready to use, See How