MimeUploadValidator
class MimeUploadValidator extends Upload_Validator (View source)
Adds an additional validation rule to Upload_Validator that attempts to detect the file extension of an uploaded file matches it's contents, which is done by detecting the MIME type and doing a fuzzy match.
Properties
protected | array | $tmpFile | Information about the temporary file produced by the PHP-runtime. |
from Upload_Validator |
protected | $errors | from Upload_Validator | ||
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. |
from Upload_Validator |
public | array | $allowedExtensions | from Upload_Validator | |
protected | string | $filterPattern | The preg_replace() pattern to use against MIME types. Used to strip out useless characters so matching of MIME types can be fuzzy. |
Methods
Return all errors that occurred while validating the temporary file.
Set information about temporary file produced by PHP.
Get maximum file size for all or specified file extension.
Set filesize maximums (in bytes or INI format).
Limit allowed file extensions. Empty by default, allowing all extensions.
Determines if the bytesize of an uploaded file is valid - can be defined on an extension-by-extension basis in $allowedMaxFileSize
Determines if the temporary file has a valid extension An empty string in the validation map indicates files without an extension.
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.
Check if the temporary file has a valid MIME type for it's extension.
Check two MIME types roughly match eachother.
Details
array
getErrors()
Return all errors that occurred while validating the temporary file.
clearErrors()
Clear out all errors
setTmpFile(array $tmpFile)
Set information about temporary file produced by PHP.
int
getAllowedMaxFileSize(string $ext = null)
Get maximum file size for all or specified file extension.
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')
array
getAllowedExtensions()
No description
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.
bool
isValidSize()
Determines if the bytesize of an uploaded file is valid - can be defined on an extension-by-extension basis in $allowedMaxFileSize
bool
isValidExtension()
Determines if the temporary file has a valid extension An empty string in the validation map indicates files without an extension.
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.
setFilterPattern($pattern)
No description
getFilterPattern()
No description
bool|null
isValidMime()
Check if the temporary file has a valid MIME type for it's extension.
array
getExpectedMimeTypes($tmpFile)
Fetches an array of valid mimetypes.
bool
compareMime(string $first, string $second)
Check two MIME types roughly match eachother.
Before we check MIME types, remove known prefixes "vnd.", "x-" etc. If there is a suffix, we'll use that to compare. Examples:
application/x-json = json application/json = json application/xhtml+xml = xml application/xml = xml