PHP 클래스 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 ], ]; ~~~
부터: 1.0
저자: Misbahul D Munir ([email protected])
상속: extends yii\base\Behavior
파일 보기 프로젝트 열기: mdmsoft/yii2-upload-file 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$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.

공개 메소드들

메소드 설명
__get ( $name )
__set ( $name, $value )
beforeDelete ( ModelEvent $event ) Event handler for beforeDelete
beforeSave ( ModelEvent $event ) Event handler for beforeSave
canGetProperty ( $name, $checkVars = true )
canSetProperty ( $name, $checkVars = true )
events ( )
getSavedFile ( ) : FileModel Get saved file
init ( )
saveUploadedFile ( boolean $deleteOldFile = null ) : boolean | null Save uploaded file into [[$uploadPath]]

메소드 상세

__get() 공개 메소드

public __get ( $name )

__set() 공개 메소드

public __set ( $name, $value )

beforeDelete() 공개 메소드

Event handler for beforeDelete
public beforeDelete ( ModelEvent $event )
$event yii\base\ModelEvent

beforeSave() 공개 메소드

Event handler for beforeSave
public beforeSave ( ModelEvent $event )
$event yii\base\ModelEvent

canGetProperty() 공개 메소드

public canGetProperty ( $name, $checkVars = true )

canSetProperty() 공개 메소드

public canSetProperty ( $name, $checkVars = true )

events() 공개 메소드

public events ( )

getSavedFile() 공개 메소드

Get saved file
public getSavedFile ( ) : FileModel
리턴 FileModel

init() 공개 메소드

public init ( )

saveUploadedFile() 공개 메소드

Save uploaded file into [[$uploadPath]]
public saveUploadedFile ( boolean $deleteOldFile = null ) : boolean | null
$deleteOldFile boolean If true and file exists, file will be deleted.
리턴 boolean | null if success return true, fault return false. Return null mean no uploaded file.

프로퍼티 상세

$attribute 공개적으로 프로퍼티

the attribute that will receive the uploaded file
public $attribute

$autoDelete 공개적으로 프로퍼티

when true then related file will be deleted on event 'beforeDelete'
public $autoDelete

$autoSave 공개적으로 프로퍼티

when true saveUploadedFile() will be called on event 'beforeSave'
public $autoSave

$deleteOldFile 공개적으로 프로퍼티

public bool $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.
public $directoryLevel

$saveCallback 공개적으로 프로퍼티

public Closure|string $saveCallback
리턴 Closure | string

$savedAttribute 공개적으로 프로퍼티

the attribute that will receive the file id
public $savedAttribute

$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 $uploadPath