PHP Class mdm\upload\UploadBehavior
Usage at [[\yii\base\Model::behaviors()]] add the following code
~~~
return [
...
[
'class' => 'mdm\upload\UploadBehavior',
'uploadPath' => '@common/upload', // default to '@runtime/upload'
'attribute' => 'file', // attribute use to receive from FileField
'savedAttribute' => 'file_id', // attribute use to receive id of file
],
];
~~~
ファイルを表示
Open project: mdmsoft/yii2-upload-file
Class Usage Examples
Public Properties
Property |
Type |
Description |
|
$attribute |
|
the attribute that will receive the uploaded file |
|
$autoDelete |
|
when true then related file will be deleted on event 'beforeDelete' |
|
$autoSave |
|
when true saveUploadedFile() will be called on event 'beforeSave' |
|
$deleteOldFile |
boolean |
|
|
$directoryLevel |
|
the level of sub-directories to store uploaded files. Defaults to 1.
If the system has huge number of uploaded files (e.g. one million), you may use a bigger value
(usually no bigger than 3). Using sub-directories is mainly to ensure the file system
is not over burdened with a single directory having too many files. |
|
$saveCallback |
Closure | string |
|
|
$savedAttribute |
|
the attribute that will receive the file id |
|
$uploadPath |
|
the directory to store uploaded files. You may use path alias here.
If not set, it will use the "upload" subdirectory under the application runtime path. |
|
Public Methods
Method Details
public __set ( $name, $value ) |
beforeDelete()
public method
Event handler for beforeDelete
public beforeDelete ( ModelEvent $event ) |
$event |
yii\base\ModelEvent |
|
beforeSave()
public method
Event handler for beforeSave
public beforeSave ( ModelEvent $event ) |
$event |
yii\base\ModelEvent |
|
canGetProperty()
public method
canSetProperty()
public method
getSavedFile()
public method
saveUploadedFile()
public method
Save uploaded file into [[$uploadPath]]
Property Details
$attribute public_oe property
the attribute that will receive the uploaded file
$autoDelete public_oe property
when true then related file will be deleted on event 'beforeDelete'
$autoSave public_oe property
when true saveUploadedFile() will be called on event 'beforeSave'
$deleteOldFile public_oe property
public bool $deleteOldFile |
return |
boolean |
|
$directoryLevel public_oe property
the level of sub-directories to store uploaded files. Defaults to 1.
If the system has huge number of uploaded files (e.g. one million), you may use a bigger value
(usually no bigger than 3). Using sub-directories is mainly to ensure the file system
is not over burdened with a single directory having too many files.
$saveCallback public_oe property
$savedAttribute public_oe property
the attribute that will receive the file id
$uploadPath public_oe property
the directory to store uploaded files. You may use path alias here.
If not set, it will use the "upload" subdirectory under the application runtime path.