PHP 클래스 yii\validators\FileValidator

Note that you should enable fileinfo PHP extension.
부터: 2.0
저자: Qiang Xue ([email protected])
상속: extends Validator
파일 보기 프로젝트 열기: yiisoft/yii2 1 사용 예제들

공개 프로퍼티들

프로퍼티 타입 설명
$checkExtensionByMimeType whether to check file type (extension) with mime-type. If extension produced by file mime-type check differs from uploaded file extension, the file will be considered as invalid.
$extensions a list of file name extensions that are allowed to be uploaded. This can be either an array or a string consisting of file extension names separated by space or comma (e.g. "gif, jpg"). Extension names are case-insensitive. Defaults to null, meaning all file name extensions are allowed.
$maxFiles the maximum file count the given attribute can hold. Defaults to 1, meaning single file upload. By defining a higher number, multiple uploads become possible. Setting it to 0 means there is no limit on the number of files that can be uploaded simultaneously. > Note: The maximum number of files allowed to be uploaded simultaneously is also limited with PHP directive max_file_uploads, which defaults to 20.
$maxSize the maximum number of bytes required for the uploaded file. Defaults to null, meaning no limit. Note, the size limit is also affected by upload_max_filesize and post_max_size INI setting and the 'MAX_FILE_SIZE' hidden field value. See FileValidator::getSizeLimit for details.
$message the error message used when a file is not uploaded correctly.
$mimeTypes a list of file MIME types that are allowed to be uploaded. This can be either an array or a string consisting of file MIME types separated by space or comma (e.g. "text/plain, image/png"). The mask with the special character * can be used to match groups of mime types. For example image/* will pass all mime types, that begin with image/ (e.g. image/jpeg, image/png). Mime type names are case-insensitive. Defaults to null, meaning all MIME types are allowed.
$minSize the minimum number of bytes required for the uploaded file. Defaults to null, meaning no limit.
$tooBig the error message used when the uploaded file is too large. You may use the following tokens in the message: - {attribute}: the attribute name - {file}: the uploaded file name - {limit}: the maximum size allowed (see FileValidator::getSizeLimit) - {formattedLimit}: the maximum size formatted with [[\yii\i18n\Formatter::asShortSize()|Formatter::asShortSize()]]
$tooMany the error message used if the count of multiple uploads exceeds limit. You may use the following tokens in the message: - {attribute}: the attribute name - {limit}: the value of [[maxFiles]]
$tooSmall the error message used when the uploaded file is too small. You may use the following tokens in the message: - {attribute}: the attribute name - {file}: the uploaded file name - {limit}: the value of [[minSize]] - {formattedLimit}: the value of [[minSize]] formatted with [[\yii\i18n\Formatter::asShortSize()|Formatter::asShortSize()]
$uploadRequired the error message used when no file is uploaded. Note that this is the text of the validation error message. To make uploading files required, you have to set [[skipOnEmpty]] to false.
$wrongExtension the error message used when the uploaded file has an extension name that is not listed in [[extensions]]. You may use the following tokens in the message: - {attribute}: the attribute name - {file}: the uploaded file name - {extensions}: the list of the allowed extensions.
$wrongMimeType the error message used when the file has an mime type that is not allowed by [[mimeTypes]] property. You may use the following tokens in the message: - {attribute}: the attribute name - {file}: the uploaded file name - {mimeTypes}: the value of [[mimeTypes]]

공개 메소드들

메소드 설명
clientValidateAttribute ( $model, $attribute, $view )
getSizeLimit ( ) : integer Returns the maximum size allowed for uploaded files.
init ( )
isEmpty ( $value, boolean $trim = false )
validateAttribute ( $model, $attribute )

보호된 메소드들

메소드 설명
getClientOptions ( Model $model, string $attribute ) : array Returns the client-side validation options.
validateExtension ( UploadedFile $file ) : boolean Checks if given uploaded file have correct type (extension) according current validator settings.
validateMimeType ( UploadedFile $file ) : boolean Checks the mimeType of the $file against the list in the [[mimeTypes]] property
validateValue ( $value )

비공개 메소드들

메소드 설명
buildMimeTypeRegexp ( string $mask ) : string Builds the RegExp from the $mask
sizeToBytes ( string $sizeStr ) : integer Converts php.ini style size to bytes

메소드 상세

clientValidateAttribute() 공개 메소드

public clientValidateAttribute ( $model, $attribute, $view )

getClientOptions() 보호된 메소드

Returns the client-side validation options.
protected getClientOptions ( Model $model, string $attribute ) : array
$model yii\base\Model the model being validated
$attribute string the attribute name being validated
리턴 array the client-side validation options

getSizeLimit() 공개 메소드

This is determined based on four factors: - 'upload_max_filesize' in php.ini - 'post_max_size' in php.ini - 'MAX_FILE_SIZE' hidden field - [[maxSize]]
public getSizeLimit ( ) : integer
리턴 integer the size limit for uploaded files.

init() 공개 메소드

public init ( )

isEmpty() 공개 메소드

public isEmpty ( $value, boolean $trim = false )
$trim boolean

validateAttribute() 공개 메소드

public validateAttribute ( $model, $attribute )

validateExtension() 보호된 메소드

Checks if given uploaded file have correct type (extension) according current validator settings.
protected validateExtension ( UploadedFile $file ) : boolean
$file yii\web\UploadedFile
리턴 boolean

validateMimeType() 보호된 메소드

Checks the mimeType of the $file against the list in the [[mimeTypes]] property
또한 보기: mimeTypes
부터: 2.0.8
protected validateMimeType ( UploadedFile $file ) : boolean
$file yii\web\UploadedFile
리턴 boolean whether the $file mimeType is allowed

validateValue() 보호된 메소드

protected validateValue ( $value )

프로퍼티 상세

$checkExtensionByMimeType 공개적으로 프로퍼티

whether to check file type (extension) with mime-type. If extension produced by file mime-type check differs from uploaded file extension, the file will be considered as invalid.
public $checkExtensionByMimeType

$extensions 공개적으로 프로퍼티

a list of file name extensions that are allowed to be uploaded. This can be either an array or a string consisting of file extension names separated by space or comma (e.g. "gif, jpg"). Extension names are case-insensitive. Defaults to null, meaning all file name extensions are allowed.
또한 보기: wrongExtension for the customized message for wrong file type.
public $extensions

$maxFiles 공개적으로 프로퍼티

the maximum file count the given attribute can hold. Defaults to 1, meaning single file upload. By defining a higher number, multiple uploads become possible. Setting it to 0 means there is no limit on the number of files that can be uploaded simultaneously. > Note: The maximum number of files allowed to be uploaded simultaneously is also limited with PHP directive max_file_uploads, which defaults to 20.
또한 보기: http://php.net/manual/en/ini.core.php#ini.max-file-uploads
또한 보기: tooMany for the customized message when too many files are uploaded.
public $maxFiles

$maxSize 공개적으로 프로퍼티

the maximum number of bytes required for the uploaded file. Defaults to null, meaning no limit. Note, the size limit is also affected by upload_max_filesize and post_max_size INI setting and the 'MAX_FILE_SIZE' hidden field value. See FileValidator::getSizeLimit for details.
또한 보기: http://php.net/manual/en/ini.core.php#ini.upload-max-filesize
또한 보기: http://php.net/post-max-size
또한 보기: getSizeLimit
또한 보기: tooBig for the customized message for a file that is too big.
public $maxSize

$message 공개적으로 프로퍼티

the error message used when a file is not uploaded correctly.
public $message

$mimeTypes 공개적으로 프로퍼티

a list of file MIME types that are allowed to be uploaded. This can be either an array or a string consisting of file MIME types separated by space or comma (e.g. "text/plain, image/png"). The mask with the special character * can be used to match groups of mime types. For example image/* will pass all mime types, that begin with image/ (e.g. image/jpeg, image/png). Mime type names are case-insensitive. Defaults to null, meaning all MIME types are allowed.
또한 보기: wrongMimeType for the customized message for wrong MIME type.
public $mimeTypes

$minSize 공개적으로 프로퍼티

the minimum number of bytes required for the uploaded file. Defaults to null, meaning no limit.
또한 보기: tooSmall for the customized message for a file that is too small.
public $minSize

$tooBig 공개적으로 프로퍼티

the error message used when the uploaded file is too large. You may use the following tokens in the message: - {attribute}: the attribute name - {file}: the uploaded file name - {limit}: the maximum size allowed (see FileValidator::getSizeLimit) - {formattedLimit}: the maximum size formatted with [[\yii\i18n\Formatter::asShortSize()|Formatter::asShortSize()]]
public $tooBig

$tooMany 공개적으로 프로퍼티

the error message used if the count of multiple uploads exceeds limit. You may use the following tokens in the message: - {attribute}: the attribute name - {limit}: the value of [[maxFiles]]
public $tooMany

$tooSmall 공개적으로 프로퍼티

the error message used when the uploaded file is too small. You may use the following tokens in the message: - {attribute}: the attribute name - {file}: the uploaded file name - {limit}: the value of [[minSize]] - {formattedLimit}: the value of [[minSize]] formatted with [[\yii\i18n\Formatter::asShortSize()|Formatter::asShortSize()]
public $tooSmall

$uploadRequired 공개적으로 프로퍼티

the error message used when no file is uploaded. Note that this is the text of the validation error message. To make uploading files required, you have to set [[skipOnEmpty]] to false.
public $uploadRequired

$wrongExtension 공개적으로 프로퍼티

the error message used when the uploaded file has an extension name that is not listed in [[extensions]]. You may use the following tokens in the message: - {attribute}: the attribute name - {file}: the uploaded file name - {extensions}: the list of the allowed extensions.
public $wrongExtension

$wrongMimeType 공개적으로 프로퍼티

the error message used when the file has an mime type that is not allowed by [[mimeTypes]] property. You may use the following tokens in the message: - {attribute}: the attribute name - {file}: the uploaded file name - {mimeTypes}: the value of [[mimeTypes]]
public $wrongMimeType