PHP code example of axelpal / yii2-attachments
1. Go to this page and download the library: Download axelpal/yii2-attachments library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
axelpal / yii2-attachments example snippets
'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
],
],
],
'controllerMap' => [
'file' => [
'class' => 'yii\console\controllers\MigrateController',
'migrationPath' => '@file/migrations'
],
],
public function behaviors()
{
return [
...
'fileBehavior' => [
'class' => \file\behaviors\FileBehavior::className()
]
...
];
}
<?= \file\components\AttachmentsInput::widget([
'id' => 'file-input', // Optional
'model' => $model,
'options' => [ // Options of the Kartik's FileInput widget
'multiple' => true, // If you want to allow multiple upload, default to false
],
'pluginOptions' => [ // Plugin options of the Kartik's FileInput widget
'maxFileCount' => 10 // Client max files
]
])
<?= \file\components\AttachmentsTable::widget(['model' => $model])
<?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', [
'class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary',
'onclick' => "$('#file-input').fileinput('upload');"
])
foreach ($model->files as $file) {
echo $file->path;
}
php yii migrate/up --migrationPath=@vendor/axelpal/yii2-attachments/migrations