Download the PHP package coderius/yii2-upload-file-behavior without Composer
On this page you can find all versions of the php package coderius/yii2-upload-file-behavior. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download coderius/yii2-upload-file-behavior
More information about coderius/yii2-upload-file-behavior
Files in coderius/yii2-upload-file-behavior
Informations about the package yii2-upload-file-behavior
Yii2 upload file behavior
About
Yii2 upload file behavior - simple wey to upload images and files to server. No need anymore wrote tonn of code in controller and else testing it by houers. As a result - saving time and labor costs for uploading files to the site. Only needed upload extention from github and past some less code to model class (\yii\db\ActiveRecord) where needed hendler uploading files. More on this below.
Installation
The preferred way to install this extension is through composer.
First download extention. Run the command in the terminal:
or add in composer.json
and run composer update
Usage
This extention created for usage in \yii\db\ActiveRecord model classes.
Configyration behavior.
- $nameOfAttributeFile = (string) default name 'file'. Virtual attribute for uploading file instance from file systrem.
- $nameOfAttributeStorage = (string) default name 'face_img'. Attribute for saving path to uploaded file in db.
- $newFileName = (string) name which is assigned to uploaded file
- $directories = (array) configs to upload folder and upload hendlers.Сonsists of separate arrays. Each array contains settings for the path to the target folder and a handler for uploading files to this folder like 'path' and 'handler' -'path' - contains path to target folder -'hendler' - Processes the downloaded file and saves to the specified in param 'path' location.
This extention created for usage in \yii\db\ActiveRecord model classes.
- So, first in model class put namespace to yii2-upload-file-behavior.
- Create public variable $file for loading file from filesystem.
- The database must have an attribute to store the file path. In example below it is 'img_src' attribute (marked like save in public function rules())
- Then past needed configs behaviors() method like in example.
!Note. Don't forget to include the dependency namespaces.
Example
Short simple config:
In this case allowed params is: 'size' & 'quality'.
Additional actions:
- Create aliases to target folders for saving uploaded files.
- Create target folders in 'frontend/web' dirrectory like example.
- Don't forget create vertual attribute. If it named like '$file', then no need set config to 'nameOfAttributeFile'(default = (string)'file').
Testing
Run tests in extention folder.
Note! For running all tests needed upload all dependencies by composer. If tested single extention, then run command from root directory where located extention:
When all dependencies downloaded run all tests in terminal from root folder:
Or for only unit:
If extention tested in app, then set correct path to phpunit and run some commands.
Credits
License
The MIT License (MIT). Please see License File for more information.
All versions of yii2-upload-file-behavior with dependencies
yiisoft/yii2 Version ^2.0.0
yiisoft/yii2-imagine Version ^2.2
mockery/mockery Version ^1.2