HumHub Documentation (unofficial)

Upload extends AbstractValidator
in package

Validator for the maximum size of a file up to a max of 2GB

Table of Contents

Constants

ATTACK  = 'fileUploadErrorAttack'
CANT_WRITE  = 'fileUploadErrorCantWrite'
EXTENSION  = 'fileUploadErrorExtension'
FILE_NOT_FOUND  = 'fileUploadErrorFileNotFound'
FORM_SIZE  = 'fileUploadErrorFormSize'
INI_SIZE  = 'fileUploadErrorIniSize'
NO_FILE  = 'fileUploadErrorNoFile'
NO_TMP_DIR  = 'fileUploadErrorNoTmpDir'
PARTIAL  = 'fileUploadErrorPartial'
UNKNOWN  = 'fileUploadErrorUnknown'

Properties

$messageTemplates  : array<string, string>
$messageVariables  : array<string, mixed>
$options  : array<string, mixed>
$abstractOptions  : AbstractOptions|array<string, mixed>
$defaultTranslator  : TranslatorInterface
Default translation object for all validate objects
$defaultTranslatorTextDomain  : string
Default text domain to be used with translator
$messageLength  : int
Limits the maximum returned length of an error message
$messageTemplates  : array<string, string>
$options  : array<string, mixed>
$value  : mixed
The value to be validated

Methods

__construct()  : mixed
Sets validator options
__get()  : mixed
Magic function returns the value of the requested property, if and only if it is the value or a message variable.
__invoke()  : bool
Invoke as command
getDefaultTranslator()  : TranslatorInterface|null
Get default translation object for all validate objects
getDefaultTranslatorTextDomain()  : string
Get default translation text domain for all validate objects
getFiles()  : array<string|int, mixed>
Returns the array of set files
getMessageLength()  : int
Returns the maximum allowed message length
getMessages()  : array<string, string>
Returns array of validation failure messages
getMessageTemplates()  : array<string, string>
Returns the message templates from the validator
getMessageVariables()  : array<int, string>
Returns an array of the names of variables that are used in constructing validation failure messages
getOption()  : mixed
Returns an option
getOptions()  : array<string, mixed>
Returns all available options
getTranslator()  : TranslatorInterface|null
Return translation object
getTranslatorTextDomain()  : string
Return the translation text domain
hasDefaultTranslator()  : bool
Is there a default translation object set?
hasTranslator()  : bool
Does this validator have its own specific translator?
isTranslatorEnabled()  : bool
Is translation enabled?
isValid()  : bool
Returns true if and only if the file was uploaded without errors
isValueObscured()  : bool
Retrieve flag indicating whether or not value should be obfuscated in messages
setDefaultTranslator()  : void
Set default translation object for all validate objects
setDefaultTranslatorTextDomain()  : void
Set default translation text domain for all validate objects
setFiles()  : $this
Sets the files to be checked
setMessage()  : $this
Sets the validation failure message template for a particular key
setMessageLength()  : void
Sets the maximum allowed message length
setMessages()  : $this
Sets validation failure message templates given as an array, where the array keys are the message keys, and the array values are the message template strings.
setOptions()  : $this
Sets one or multiple options
setTranslator()  : $this
Set translation object
setTranslatorEnabled()  : $this
Indicate whether or not translation should be enabled
setTranslatorTextDomain()  : $this
Set translation text domain
setValueObscured()  : $this
Set flag indicating whether or not value should be obfuscated in messages
createMessage()  : null|string
Constructs and returns a validation failure message with the given message key and value.
error()  : void
getValue()  : mixed
Returns the validation value
setValue()  : void
Sets the value to be validated and clears the messages and errors arrays
throwError()  : false
Throws an error of the given type
translateMessage()  : string
Translate a validation message

Constants

ATTACK

public mixed ATTACK = 'fileUploadErrorAttack'

CANT_WRITE

public mixed CANT_WRITE = 'fileUploadErrorCantWrite'

EXTENSION

public mixed EXTENSION = 'fileUploadErrorExtension'

FILE_NOT_FOUND

public mixed FILE_NOT_FOUND = 'fileUploadErrorFileNotFound'

FORM_SIZE

public mixed FORM_SIZE = 'fileUploadErrorFormSize'

INI_SIZE

public mixed INI_SIZE = 'fileUploadErrorIniSize'
Tags
const

string Error constants

NO_FILE

public mixed NO_FILE = 'fileUploadErrorNoFile'

NO_TMP_DIR

public mixed NO_TMP_DIR = 'fileUploadErrorNoTmpDir'

PARTIAL

public mixed PARTIAL = 'fileUploadErrorPartial'

UNKNOWN

public mixed UNKNOWN = 'fileUploadErrorUnknown'

Properties

$abstractOptions

protected AbstractOptions|array<string, mixed> $abstractOptions = [ 'messages' => [], // Array of validation failure messages 'messageTemplates' => [], // Array of validation failure message templates 'messageVariables' => [], // Array of additional variables available for validation failure messages 'translator' => null, // Translation object to used -> Translator\TranslatorInterface 'translatorTextDomain' => null, // Translation text domain 'translatorEnabled' => true, // Is translation enabled? 'valueObscured' => false, ]

$defaultTranslatorTextDomain

Default text domain to be used with translator

protected static string $defaultTranslatorTextDomain = 'default'

$messageLength

Limits the maximum returned length of an error message

protected static int $messageLength = -1

$messageTemplates

protected array<string, string> $messageTemplates = [self::INI_SIZE => "File '%value%' exceeds upload_max_filesize directive in php.ini", self::FORM_SIZE => "File '%value%' exceeds the MAX_FILE_SIZE directive that was " . 'specified in the HTML form', self::PARTIAL => "File '%value%' was only partially uploaded", self::NO_FILE => "File '%value%' was not uploaded", self::NO_TMP_DIR => "Missing a temporary folder to store '%value%'", self::CANT_WRITE => "Failed to write file '%value%' to disk", self::EXTENSION => "A PHP extension stopped uploading the file '%value%'", self::ATTACK => "File '%value%' was illegally uploaded. This could be a possible attack", self::FILE_NOT_FOUND => "File '%value%' was not found", self::UNKNOWN => "Unknown error while uploading file '%value%'"]

Error message templates

$options

protected array<string, mixed> $options = ['files' => []]

Methods

__construct()

Sets validator options

public __construct([array<string|int, mixed>|Traversable $options = [] ]) : mixed

The array $files must be given in syntax of Laminas\File\Transfer\Transfer to be checked If no files are given the $_FILES array will be used automatically. NOTE: This validator will only work with HTTP POST uploads!

Parameters
$options : array<string|int, mixed>|Traversable = []

Array of files in syntax of \Laminas\File\Transfer\Transfer

__get()

Magic function returns the value of the requested property, if and only if it is the value or a message variable.

public __get(string $property) : mixed
Parameters
$property : string
Tags
throws
InvalidArgumentException

__invoke()

Invoke as command

public __invoke(mixed $value) : bool
Parameters
$value : mixed
Return values
bool

getDefaultTranslatorTextDomain()

Get default translation text domain for all validate objects

public static getDefaultTranslatorTextDomain() : string
Return values
string

getFiles()

Returns the array of set files

public getFiles([string $file = null ]) : array<string|int, mixed>
Parameters
$file : string = null

(Optional) The file to return in detail

Tags
throws
InvalidArgumentException

If file is not found.

Return values
array<string|int, mixed>

getMessageLength()

Returns the maximum allowed message length

public static getMessageLength() : int
Return values
int

getMessages()

Returns array of validation failure messages

public getMessages() : array<string, string>
Return values
array<string, string>

getMessageTemplates()

Returns the message templates from the validator

public getMessageTemplates() : array<string, string>
Return values
array<string, string>

getMessageVariables()

Returns an array of the names of variables that are used in constructing validation failure messages

public getMessageVariables() : array<int, string>
Return values
array<int, string>

getOption()

Returns an option

public getOption(string $option) : mixed
Parameters
$option : string

Option to be returned

Tags
throws
InvalidArgumentException
Return values
mixed

Returned option

getOptions()

Returns all available options

public getOptions() : array<string, mixed>
Return values
array<string, mixed>

Array with all available options

getTranslatorTextDomain()

Return the translation text domain

public getTranslatorTextDomain() : string
Return values
string

hasDefaultTranslator()

Is there a default translation object set?

public static hasDefaultTranslator() : bool
Return values
bool

hasTranslator()

Does this validator have its own specific translator?

public hasTranslator() : bool
Return values
bool

isTranslatorEnabled()

Is translation enabled?

public isTranslatorEnabled() : bool
Return values
bool

isValid()

Returns true if and only if the file was uploaded without errors

public isValid(string $value[, mixed $file = null ]) : bool
Parameters
$value : string

Single file to check for upload errors, when giving null the $_FILES array from initialization will be used

$file : mixed = null
Return values
bool

isValueObscured()

Retrieve flag indicating whether or not value should be obfuscated in messages

public isValueObscured() : bool
Return values
bool

setDefaultTranslatorTextDomain()

Set default translation text domain for all validate objects

public static setDefaultTranslatorTextDomain([string $textDomain = 'default' ]) : void
Parameters
$textDomain : string = 'default'

setFiles()

Sets the files to be checked

public setFiles([array<string|int, mixed> $files = [] ]) : $this
Parameters
$files : array<string|int, mixed> = []

The files to check in syntax of \Laminas\File\Transfer\Transfer

Return values
$this

Provides a fluent interface

setMessage()

Sets the validation failure message template for a particular key

public setMessage(string $messageString[, string|null $messageKey = null ]) : $this
Parameters
$messageString : string
$messageKey : string|null = null

OPTIONAL

Tags
throws
InvalidArgumentException
Return values
$this

Provides a fluent interface

setMessageLength()

Sets the maximum allowed message length

public static setMessageLength([int $length = -1 ]) : void
Parameters
$length : int = -1

setMessages()

Sets validation failure message templates given as an array, where the array keys are the message keys, and the array values are the message template strings.

public setMessages(array<string, string> $messages) : $this
Parameters
$messages : array<string, string>
Return values
$this

setOptions()

Sets one or multiple options

public setOptions([array<string, mixed>|Traversable<string, mixed> $options = [] ]) : $this
Parameters
$options : array<string, mixed>|Traversable<string, mixed> = []

Options to set

Tags
throws
InvalidArgumentException

If $options is not an array or Traversable.

Return values
$this

Provides fluid interface

setTranslatorEnabled()

Indicate whether or not translation should be enabled

public setTranslatorEnabled([bool $enabled = true ]) : $this
Parameters
$enabled : bool = true
Return values
$this

setTranslatorTextDomain()

Set translation text domain

public setTranslatorTextDomain([string $textDomain = 'default' ]) : $this
Parameters
$textDomain : string = 'default'
Return values
$this

setValueObscured()

Set flag indicating whether or not value should be obfuscated in messages

public setValueObscured(bool $flag) : $this
Parameters
$flag : bool
Return values
$this

createMessage()

Constructs and returns a validation failure message with the given message key and value.

protected createMessage(string $messageKey, string|array<string|int, mixed>|object $value) : null|string

Returns null if and only if $messageKey does not correspond to an existing template.

If a translator is available and a translation exists for $messageKey, the translation will be used.

Parameters
$messageKey : string
$value : string|array<string|int, mixed>|object
Return values
null|string

error()

protected error(string|null $messageKey[, null|string|array<string|int, mixed>|object $value = null ]) : void
Parameters
$messageKey : string|null
$value : null|string|array<string|int, mixed>|object = null

OPTIONAL

getValue()

Returns the validation value

protected getValue() : mixed
Return values
mixed

Value to be validated

setValue()

Sets the value to be validated and clears the messages and errors arrays

protected setValue(mixed $value) : void
Parameters
$value : mixed

throwError()

Throws an error of the given type

protected throwError(array<string|int, mixed>|string|UploadedFileInterface $file, string $errorType) : false
Parameters
$file : array<string|int, mixed>|string|UploadedFileInterface
$errorType : string
Return values
false

translateMessage()

Translate a validation message

protected translateMessage(string $messageKey, string $message) : string
Parameters
$messageKey : string
$message : string
Return values
string

        
On this page

Search results