Download the PHP package liyunfang/yii2-upload-behavior without Composer
On this page you can find all versions of the php package liyunfang/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 中文
Note: Reference project https://github.com/mongosoft/yii2-upload-behavior
This behavior automatically uploads file and fills the specified attribute with a value of the name of the uploaded file.
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:
Example view single file:
Example view multiple file:
Upload image and create thumbnails
Attach the behavior in your model:
Example view single file:
Example view multiple file:
if you install https://github.com/kartik-v/yii2-widget-fileinput
Behavior Options
- attributes - The attributes which Hold collection for 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.
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.