PHP Класс yii\validators\FileValidator

Note that you should enable fileinfo PHP extension.
С версии: 2.0
Автор: Qiang Xue ([email protected])
Наследование: extends Validator
Показать файл Открыть проект Примеры использования класса

Открытые свойства

Свойство Тип Описание
$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