Download the PHP package xisio/yii2-upload-behavior without Composer
On this page you can find all versions of the php package xisio/yii2-upload-behavior. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package yii2-upload-behavior
Upload behavior for Yii 2
This behavior automatically uploads file and fills the specified attribute with a value of the name of the uploaded file.
In this behaviour added ability to load file from URL and local files, and attach behavior for two or more attributes.
This is an enhanced version of https://github.com/mohorev/yii2-upload-behavior/
Installation
The preferred way to install this extension via composer.
Either run
or add this code line to the require
section of your composer.json
file:
Usage
Upload file from input forms
Attach the behavior in your model:
Set model scenario in controller action:
Example view file:
Upload file from url
To load file from url
Upload file from file
To load file from local file
Get path in you application
Get upload url
Get upload path
Upload image and create thumbnails
Thumbnails processing requires yiisoft/yii2-imagine to be installed.
Attach the behavior in your model:
Flexible configuration for path and URL generation
More flexible configuration for path
and/or url
behavior properties is that to use
callbacks or array for defining path
or url
generation logic.
I. Via callbacks
II. Via array configuration by defining class and its static methods for path/URL generation
Example view file:
Behavior Options
- attribute - The attribute which holds the attachment
- scenarios - The scenarios in which the behavior will be triggered
- instanceByName - Getting file instance by name, If you use UploadBehavior in
RESTfull
application and you do not need a prefix of the model name, set the propertyinstanceByName = false
, default value isfalse
- path - the base path or path alias to the directory in which to save files.
- url - the base URL or path alias for this file
- generateNewName - Set true or anonymous function takes the old filename and returns a new name, default value is
true
- unlinkOnSave - If
true
current attribute file will be deleted, default value istrue
- unlinkOnDelete - If
true
current attribute file will be deleted after model deletion. - deleteEmptyDir - If
true
the empty directory will be deleted after model deletion, default value istrue
.
UploadImageBehavior additional Options
- createThumbsOnSave - If
true
create all thumbs profiles on image upload - createThumbsOnRequest - If
true
create thumb only for profile request bygetThumbUploadUrl('attribute', 'profile_name)
method. Iftrue
recommend to setcreateThumbsOnSave
tofalse
- deleteOriginalFile - If
true
the original upload image will be deleted after images thumbs was generated, default value isfalse
.\ Attention don't use with createThumbsOnRequest options, because thumbs generate on request (NOT after upload image) and after first profile thumb generation original file will be deleted!
Attention!
It is prefered to use immutable placeholder in url
and path
options, other words try don't use related attributes that can be changed. There's bad practice. For example:
If related model attribute slug
will change, you must change folders' names too, otherwise behavior will works not correctly.
Authors
- Alexander Mohorev [email protected]
- Alexey Samoylov [email protected]
- Aleksandr Pogorelov [email protected]
All versions of yii2-upload-behavior with dependencies
yiisoft/yii2 Version ~2.0.0
yiisoft/yii2-imagine Version ~2.2.0
yiisoft/yii2-httpclient Version ~2.0.0