PHP 클래스 mongosoft\file\UploadBehavior

To use UploadBehavior, insert the following code to your ActiveRecord class: php use mongosoft\file\UploadBehavior; function behaviors() { return [ [ 'class' => UploadBehavior::className(), 'attribute' => 'file', 'scenarios' => ['insert', 'update'], 'path' => '@webroot/upload/{id}', 'url' => '@web/upload/{id}', ], ]; }
저자: Alexander Mohorev ([email protected])
저자: Alexey Samoylov ([email protected])
상속: extends yii\base\Behavior
파일 보기 프로젝트 열기: mongosoft/yii2-upload-behavior 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$attribute the attribute which holds the attachment.
$deleteTempFile boolean whether to delete the temporary file after saving.
$generateNewName generate a new unique name for the file set true or anonymous function takes the old filename and returns a new name.
$instanceByName Getting file instance by name
$path the base path or path alias to the directory in which to save files.
$scenarios the scenarios in which the behavior will be triggered
$unlinkOnDelete If true current attribute file will be deleted after model deletion.
$unlinkOnSave If true current attribute file will be deleted
$url the base URL or path alias for this file

공개 메소드들

메소드 설명
afterDelete ( ) This method is invoked after deleting a record.
afterSave ( ) This method is called at the end of inserting or updating a record.
beforeSave ( ) This method is called at the beginning of inserting or updating a record.
beforeValidate ( ) This method is invoked before validation starts.
events ( )
getUploadPath ( string $attribute, boolean $old = false ) : string | null Returns file path for the attribute.
getUploadUrl ( string $attribute ) : string | null Returns file url for the attribute.
init ( )
sanitize ( string $filename ) : boolean Replaces characters in strings that are illegal/unsafe for filename.

보호된 메소드들

메소드 설명
afterUpload ( ) This method is invoked after uploading a file.
delete ( string $attribute, boolean $old = false ) Deletes old file.
generateFileName ( UploadedFile $file ) : string Generates random filename.
getFileName ( UploadedFile $file ) : string
resolvePath ( $path ) Replaces all placeholders in path variable with corresponding values.
save ( UploadedFile $file, string $path ) : boolean Saves the uploaded file.

메소드 상세

afterDelete() 공개 메소드

This method is invoked after deleting a record.
public afterDelete ( )

afterSave() 공개 메소드

This method is called at the end of inserting or updating a record.
public afterSave ( )

afterUpload() 보호된 메소드

The default implementation raises the [[EVENT_AFTER_UPLOAD]] event. You may override this method to do postprocessing after the file is uploaded. Make sure you call the parent implementation so that the event is raised properly.
protected afterUpload ( )

beforeSave() 공개 메소드

This method is called at the beginning of inserting or updating a record.
public beforeSave ( )

beforeValidate() 공개 메소드

This method is invoked before validation starts.
public beforeValidate ( )

delete() 보호된 메소드

Deletes old file.
protected delete ( string $attribute, boolean $old = false )
$attribute string
$old boolean

events() 공개 메소드

public events ( )

generateFileName() 보호된 메소드

Generates random filename.
protected generateFileName ( UploadedFile $file ) : string
$file yii\web\UploadedFile
리턴 string

getFileName() 보호된 메소드

protected getFileName ( UploadedFile $file ) : string
$file yii\web\UploadedFile
리턴 string

getUploadPath() 공개 메소드

Returns file path for the attribute.
public getUploadPath ( string $attribute, boolean $old = false ) : string | null
$attribute string
$old boolean
리턴 string | null the file path.

getUploadUrl() 공개 메소드

Returns file url for the attribute.
public getUploadUrl ( string $attribute ) : string | null
$attribute string
리턴 string | null

init() 공개 메소드

public init ( )

resolvePath() 보호된 메소드

Replaces all placeholders in path variable with corresponding values.
protected resolvePath ( $path )

sanitize() 공개 정적인 메소드

#my* unsaf&file:name?".png
public static sanitize ( string $filename ) : boolean
$filename string the source filename to be "sanitized"
리턴 boolean string the sanitized filename

save() 보호된 메소드

Saves the uploaded file.
protected save ( UploadedFile $file, string $path ) : boolean
$file yii\web\UploadedFile the uploaded file instance
$path string the file path used to save the uploaded file
리턴 boolean true whether the file is saved successfully

프로퍼티 상세

$attribute 공개적으로 프로퍼티

the attribute which holds the attachment.
public $attribute

$deleteTempFile 공개적으로 프로퍼티

whether to delete the temporary file after saving.
public bool $deleteTempFile
리턴 boolean

$generateNewName 공개적으로 프로퍼티

generate a new unique name for the file set true or anonymous function takes the old filename and returns a new name.
또한 보기: self::generateFileName()
public $generateNewName

$instanceByName 공개적으로 프로퍼티

Getting file instance by name
public $instanceByName

$path 공개적으로 프로퍼티

the base path or path alias to the directory in which to save files.
public $path

$scenarios 공개적으로 프로퍼티

the scenarios in which the behavior will be triggered
public $scenarios

$unlinkOnDelete 공개적으로 프로퍼티

If true current attribute file will be deleted after model deletion.
public $unlinkOnDelete

$unlinkOnSave 공개적으로 프로퍼티

If true current attribute file will be deleted
public $unlinkOnSave

$url 공개적으로 프로퍼티

the base URL or path alias for this file
public $url