PHP code example of dlds / yii2-attachments
1. Go to this page and download the library: Download dlds/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/ */
dlds / yii2-attachments example snippets
'modules' => [
...
'attachments' => [
'class' => dlds\attachments\Module::className(),
'tempPath' => '@app/uploads/temp',
'storePath' => '@app/uploads/store'
]
...
]
public function behaviors()
{
return [
...
'attachmentBehavior' => [
'class' => \dlds\attachments\behaviors\AttachmentBehavior::className()
]
...
];
}
<?= \kartik\file\FileInput::widget([
'name' => 'file[]',
'id' => 'file-input',
'options' => [
'multiple' => true, // false if you want to allow upload a single file
],
'pluginOptions' => [
'uploadUrl' => yii\helpers\Url::toRoute('/attachments/file/upload'), // remove this if you don't want to use AJAX uploading
'initialPreview' => $model->isNewRecord ? [] : $model->getInitialPreview(),
'initialPreviewConfig' => $model->isNewRecord ? [] : $model->getInitialPreviewConfig(),
// other options
]
]);
<?= \dlds\attachments\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');"
])
php composer.phar
php yii migrate/up --migrationPath=@vendor/dlds/yii2-attachments/migrations