Download the PHP package mongosoft/yii2-upload-behavior without Composer
On this page you can find all versions of the php package mongosoft/yii2-upload-behavior. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Rated 3.00 based on 1 reviews
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. This code is inspired by, but not derived from, https://github.com/yii-dream-team/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
Attach the behavior in your model:
Set model scenario in controller action:
Example view file:
Upload image and create thumbnails
Thumbnails processing requires yiisoft/yii2-imagine to be installed.
Attach the behavior in your model:
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. - deleteOriginalFile - Only for UploadImageBehavior. If
true
original image file will be deleted after thumbs generating, default value isfalse
.
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.