PHP code example of mix8872 / files-attacher

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

    

mix8872 / files-attacher example snippets


'modules' => [
	'filesAttacher' => [
		'class' => 'mix8872\filesAttacher\Module',
		'as access' => [
			'class' => 'yii\filters\AccessControl',
			'rules' => [
				[
					'controllers' => ['filesAttacher/default'],
					'allow' => true,
					'roles' => ['admin']
				],
			]
		],
		'parameters' => [
            'imageResize' => [
                'galleryMiddle' => ['width' => '880', 'height' => '587', 'model' => ['common\modules\imageslider\models\ImageSlider']],
                'galleryPreview' => ['width' => '120', 'height' => '60', 'model' => ['common\modules\imageslider\models\ImageSlider']]
            ],
            'sizesNameBy' => 'template', // or 'key', optionally, default 'size'
            'sizesNameTemplate' => '_resize_%k-%s', //optionally, if sizesNameBy set to 'template'
            'origResize' => ['width' => '1024', 'height' => '768', 'model' => ['common\modules\imageslider\models\ImageSlider']], //optionally
            'imgProcessDriver' => 'imagick', //or 'imagick', optionally, default 'gd',
            'filesNameBy' => 'translit', // optionally, by default naming is random string
            'savePath' => '/uploads/attachments/', // optionally, default save path is '/uploads/attachments/'
        ],
	],
	// ... other modules definition
],

public function behaviors()
    {
        return [
            [
                'class' => \mix8872\filesAttacher\behaviors\FileAttachBehavior::class,
                'tags' => ['images','videos'],
                'deleteOld' => []
            ],
			// ... other behaviors
        ];
    }

use mix8872\filesAttacher\widgets\FilesWidget;

// ... you view code

 $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data']]); // IMPORTANT 

$files = $model->getFiles('tag'); //array of file objects

php composer.phar