class Upload_Validator (View source)

Properties

protected array $tmpFile

Information about the temporary file produced by the PHP-runtime.

protected $errors
public array $allowedMaxFileSize

Restrict filesize for either all filetypes or a specific extension, with extension-name as array-key and the size-restriction in bytes as array-value.

public array $allowedExtensions

Methods

public
array
getErrors()

Return all errors that occurred while validating the temporary file.

public
clearErrors()

Clear out all errors

public
setTmpFile(array $tmpFile)

Set information about temporary file produced by PHP.

public
int
getAllowedMaxFileSize(string $ext = null)

Get maximum file size for all or specified file extension.

public
setAllowedMaxFileSize(array|int $rules)

Set filesize maximums (in bytes or INI format).

public
array
getAllowedExtensions()

No description

public
setAllowedExtensions(array $rules)

Limit allowed file extensions. Empty by default, allowing all extensions.

public
bool
isValidSize()

Determines if the bytesize of an uploaded file is valid - can be defined on an extension-by-extension basis in $allowedMaxFileSize

public
bool
isValidExtension()

Determines if the temporary file has a valid extension An empty string in the validation map indicates files without an extension.

public
bool
validate()

Run through the rules for this validator checking against the temporary file set by setTmpFile() to see if the file is deemed valid or not.

Details

array getErrors()

Return all errors that occurred while validating the temporary file.

Return Value

array

clearErrors()

Clear out all errors

setTmpFile(array $tmpFile)

Set information about temporary file produced by PHP.

Parameters

array $tmpFile

int getAllowedMaxFileSize(string $ext = null)

Get maximum file size for all or specified file extension.

Parameters

string $ext

Return Value

int

Filesize in bytes

setAllowedMaxFileSize(array|int $rules)

Set filesize maximums (in bytes or INI format).

Automatically converts extensions to lowercase for easier matching.

Example:

array('*' => 200, 'jpg' => 1000, '[doc]' => '5m')

Parameters

array|int $rules

array getAllowedExtensions()

No description

Return Value

array

setAllowedExtensions(array $rules)

Limit allowed file extensions. Empty by default, allowing all extensions.

To allow files without an extension, use an empty string. See File::$allowed_extensions to get a good standard set of extensions that are typically not harmful in a webserver context. See setAllowedMaxFileSize() to limit file size by extension.

Parameters

array $rules

List of extensions

bool isValidSize()

Determines if the bytesize of an uploaded file is valid - can be defined on an extension-by-extension basis in $allowedMaxFileSize

Return Value

bool

bool isValidExtension()

Determines if the temporary file has a valid extension An empty string in the validation map indicates files without an extension.

Return Value

bool

bool validate()

Run through the rules for this validator checking against the temporary file set by setTmpFile() to see if the file is deemed valid or not.

Return Value

bool