PHP code example of laco-agency / uploader

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

    

laco-agency / uploader example snippets



 'uploader' => ['class' => '\laco\uploader\Module'],


use laco\uploader\processor\ImageProcessor;
use laco\uploader\storage\ModelStorage;
use laco\uploader\storageFile\StorageFile;
use laco\uploader\behaviors\UploadBehavior;

class Model extends yii\db\ActiveRecord
{

 public function behaviors()
    {
        return [
            [
                'class' => UploadBehavior::className(),
                'uploadAttributes' => [
                    'image_preview' => [
                        'class' => StorageFile::className(),
                        'storage' => ModelStorage::className(),
                        'processOptions' => [
                            'origin' => [
                                'class' => ImageProcessor::className(),
                                'width' => 912,
                                'height' => 570,
                                'crop' => true
                            ],
                            'thumb' => [
                                'class' => ImageProcessor::className(),
                                'width' => 244,
                                'height' => 138,
                                'crop' => true
                            ],
                        ]
                    ],                   
                ]
            ]
        ];
    }
 
   
   // Configure validation rules for files attributes as regular   
    public function rules()
    {
        return [
            [['image_preview'], 'image'],
        ];
    }
}

use \laco\uploader\widgets\image\Image;

    <?= $form->field($model, 'image_preview')->widget(Image::className(),
    ['imageUrl' => $model->getFileUrl('image_preview', 'thumb')]); 

use laco\uploader\widgets\tinymce\TinyMce;

<?= $form->field($model, 'content')->widget(TinyMce::className());