PHP code example of templesuite / yii2-attachments

1. Go to this page and download the library: Download templesuite/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/ */

    

templesuite / yii2-attachments example snippets


	'modules' => [
		...
		'attachments' => [
			'class' => templesuite\attachments\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}}' // Optional, default to 'attach_file'
		]
		...
	]
	

    	'controllerMap' => [
		...
		'migrate' => [
			'class' => 'yii\console\controllers\MigrateController',
			'migrationNamespaces' => [
				'templesuite\attachments\migrations',
			],
		],
		...
    	],
	

	public function behaviors()
	{
		return [
			...
			'fileBehavior' => [
				'class' => \templesuite\attachments\behaviors\FileBehavior::className()
			]
			...
		];
	}
	

	<?= \templesuite\attachments\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
		]
	]) 

	<?= \templesuite\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');"
	]) 

	foreach ($model->files as $file) {
        echo $file->path;
    }
    

	php composer.phar 

	php yii migrate/up
	
$file->path