Validate/File/MimeType.php
Zend Framework
LICENSE
This source file is subject to the new BSD license that is bundled
with this package in the file LICENSE.txt.
It is also available through the world-wide-web at this URL:
http://framework.zend.com/license/new-bsd
If you did not receive a copy of the license and are unable to
obtain it through the world-wide-web, please send an email
to license@zend.com so we can send you a copy immediately.
- Category
- Zend
- Copyright
- Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
- Package
- Zend_Validate
- Version
- $Id: MimeType.php 25175 2012-12-22 20:47:08Z rob $
\Zend_Validate_File_MimeType
Package: Zend\ValidateValidator for the mime type of a file
- Parent(s)
- \Zend_Validate_Abstract
- Children
- \Zend_Validate_File_ExcludeMimeType
- \Zend_Validate_File_IsImage
- \Zend_Validate_File_IsCompressed
- Category
- Zend
- Copyright
- Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
Constants


FALSE_TYPE
= 'fileMimeTypeFalse'


NOT_DETECTED
= 'fileMimeTypeNotDetected'


NOT_READABLE
= 'fileMimeTypeNotReadable'
Properties



boolean $_headerCheck = false
Option to allow header check
Default valuefalse
Details- Type
- boolean



array $_magicFiles = array('/usr/share/misc/magic', '/usr/share/misc/magic.mime', '/usr/share/misc/magic.mgc', '/usr/share/mime/magic', '/usr/share/mime/magic.mime', '/usr/share/mime/magic.mgc', '/usr/share/file/magic', '/usr/share/file/magic.mime', '/usr/share/file/magic.mgc')
If no $_ENV['MAGIC'] is set, try and autodiscover it based on common locations
Default valuearray('/usr/share/misc/magic', '/usr/share/misc/magic.mime', '/usr/share/misc/magic.mgc', '/usr/share/mime/magic', '/usr/share/mime/magic.mime', '/usr/share/mime/magic.mgc', '/usr/share/file/magic', '/usr/share/file/magic.mime', '/usr/share/file/magic.mgc')
Details- Type
- array



array $_messageTemplates = array(self::FALSE_TYPE => "File '%value%' has a false mimetype of '%type%'", self::NOT_DETECTED => "The mimetype of file '%value%' could not be detected", self::NOT_READABLE => "File '%value%' is not readable or does not exist")
Validation failure message template definitions
Default valuearray(self::FALSE_TYPE => "File '%value%' has a false mimetype of '%type%'", self::NOT_DETECTED => "The mimetype of file '%value%' could not be detected", self::NOT_READABLE => "File '%value%' is not readable or does not exist")
Details- Type
- array



array $_messageVariables = array('type' => '_type')
Additional variables available for validation failure messages
Default valuearray('type' => '_type')
Details- Type
- array



boolean $_tryCommonMagicFiles = true
Indicates whether use of $_magicFiles should be attempted.
Default valuetrue
Details- Type
- boolean
Methods



__get(string $property) : mixed
inheritedMagic function returns the value of the requested property, if and only if it is the value or a
message variable.
Inherited from:
\Zend_Validate_Abstract::__get() ParametersName | Type | Description |
---|
$property | string | |
---|
ReturnsThrows 


_createMessage(string $messageKey, string $value) : 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.
ParametersName | Type | Description |
---|
$messageKey | string | |
---|
$value | string | |
---|
Returns


_error(string $messageKey, string $value = null) : void
ParametersName | Type | Description |
---|
$messageKey | string | |
---|
$value | string | OPTIONAL |
---|



_throw(string $file, string $errorType) : false
Throws an error of the given type
ParametersName | Type | Description |
---|
$file | string | |
---|
$errorType | string | |
---|
Returns 


addMimeType(string | array $mimetype) : \Zend_Validate_File_Extension
ParametersName | Type | Description |
---|
$mimetype | string | array | The mimetypes to add for validation |
---|
Returns 


enableHeaderCheck( $headerCheck = true) : \Zend_Validate_File_MimeType
Defines if the http header should be used
Note that this is unsave and therefor the default value is false
ParametersName | Type | Description |
---|
$headerCheck | | |
---|
Returns 


getMagicFile() : string
Returns the actual set magicfile
Note that for PHP 5.3.0 or higher, we don't use $_ENV['MAGIC'] or try to
find a magic file in a common location as PHP now has a built-in internal
magic file.
Returns


getMessages() : array
The array keys are validation failure message identifiers,
and the array values are the corresponding human-readable message strings.
If isValid() was never called or if the most recent isValid() call
returned true, then this method returns an empty array.
Returns


getMimeType(boolean $asArray = false) : string | array
Returns the set mimetypes
ParametersName | Type | Description |
---|
$asArray | boolean | Returns the values as array, when false an concated string is returned |
---|
ReturnsType | Description |
---|
string | array | |



isValid(string $value, array $file = null) : boolean
Defined by Zend_Validate_Interface
Returns true if the mimetype of the file matches the given ones. Also parts
of mimetypes can be checked. If you give for example "image" all image
mime types will be accepted like "image/gif", "image/jpeg" and so on.
ParametersName | Type | Description |
---|
$value | string | Real file to check for mimetype |
---|
$file | array | File data from Zend_File_Transfer |
---|
ReturnsThrows


setMagicFile(string $file) : \Zend_Validate_File_MimeType
Sets the magicfile to use
if null, the MAGIC constant from php is used
if the MAGIC file is errorous, no file will be set
ParametersName | Type | Description |
---|
$file | string | |
---|
ReturnsThrows 


setMessage(string $messageString, string $messageKey = null) : \Zend_Validate_Abstract
ParametersName | Type | Description |
---|
$messageString | string | |
---|
$messageKey | string | OPTIONAL |
---|
ReturnsThrows 


setMessages(array $messages) : \Zend_Validate_Abstract
inheritedSets 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.
Inherited from:
\Zend_Validate_Abstract::setMessages() ParametersName | Type | Description |
---|
$messages | array | |
---|
Returns 


setMimeType(string | array $mimetype) : \Zend_Validate_File_Extension
ParametersName | Type | Description |
---|
$mimetype | string | array | The mimetypes to validate |
---|
Returns 


setTryCommonMagicFilesFlag(boolean $flag = true) : \Zend_Validate_File_MimeType
Enables or disables attempts to try the common magic file locations
specified by Zend_Validate_File_MimeType::_magicFiles
ParametersName | Type | Description |
---|
$flag | boolean | |
---|
ReturnsDetails- See
- \http://framework.zend.com/issues/browse/ZF-11784



shouldTryCommonMagicFiles() : boolean
Accessor for Zend_Validate_File_MimeType::_magicFiles
ReturnsDetails- See
- \http://framework.zend.com/issues/browse/ZF-11784