2017 © Pedro Peláez
 

yii2-extension yii2-uploader

Images uploader

image

pc-brainy/yii2-uploader

Images uploader

  • Wednesday, July 25, 2018
  • by pc-brainy
  • Repository
  • 1 Watchers
  • 0 Stars
  • 90 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 3 % Grown

The README.md

Uploader

Uploader, (*1)

Installation

The preferred way to install this extension is through composer., (*2)

Either run, (*3)

composer require pc-brainy/yii2-uploader "dev-master"

or add, (*4)

"pc-brainy/yii2-uploader" : "dev-master"

to the require section of your application's composer.json file., (*5)

Configure

  1. Add in common/config/main.php 'controllerMap' => [ 'uploader' => 'brainy\uploader\controllers\UploaderController', ],, (*6)

    Yii::setAlias('storage', dirname(dirname(DIR)) . '/storage'); Yii::setAlias('images', dirname(dirname(DIR)) . '/storage/images');, (*7)

Usage

with default parameters, (*8)

<?php
    use brainy\uploader\Uploader;
    echo Uploader::widget();
?>

with parameters, (*9)

["\brainy\uploader\models\Photo", "image"],
        'modal'=>true,
        'options' => [
            'multiple' => true,
            'accept' => 'image/*',
        ],
        'pluginOptions' => [
            'uploadExtraData'=>[
                    'thumbnailSize'=>[320, 200],
                    'imgFolderPath'=>Yii::getAlias('@images').'/tests',
                    'multiplePath'=>[
                        'full'=>false,
                        'middle'=>[400, 400],
                        'thumb'=>[150, 150]
                    ],      
                    'filename'=>$product->name,//product name, description, predefined string, etc
                    'slug'=>true,
                    'uniqid'=>true,

            ],
        ]
    ]);
?>

Parameters

model
    ["\brainy\uploader\models\Photo", "image"] //[class, attribute]
    modelul AR in care vor fi salvate informatiile despre imagini

slug
    true/false - convert filename to slugged name
    converteste denumirea fisierului minuscule-minuscule.ext

uniqid
    true/false - add an uniq ID to filename
    adauga la numele fisierului un id unic

modal = true
    display a button to launch modal window of uploader

thumbnailSize
    not set of set false = keep actual size
    [300,200] => [width,height]px
    300 => square of 300px

uploadUrl
    set only if will be used your function to upload


multiplePath
    'multiplePath'=>[
        'folderName'=>false, //save original size
        'anotherFolderName'=>[400, 400], //save thumbnails with 400px X 400px
        'andAnotherFolderName'=>[150, 150]  //save thumbnails with 150px X 150px
        .......
    ],

filename
    a string to be used as filename for saved file

dbFields
    'dbFields'=>[
        'owner_id'=> $product->id, 
        'order'=>'999'
    ]
    pairs of informations to be saved in model in various field, along filename
    'field'=>'value'


The Versions

25/07 2018