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-2014 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
- Package
- Zend_Validate
- Version
- $Id$
\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-2014 Zend Technologies USA Inc. (http://www.zend.com)
- License
- New BSD License
Constants


FALSE_TYPE
= 'fileMimeTypeFalse'- Const
- Error type constants


NOT_DETECTED
= 'fileMimeTypeNotDetected'

NOT_READABLE
= 'fileMimeTypeNotReadable'Properties



boolean $_headerCheck = falseOption to allow header check
Default valuefalseDetails- 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



boolean $_tryCommonMagicFiles = trueIndicates whether use of $_magicFiles should be attempted.
Default valuetrueDetails- Type
- boolean
Methods



__construct(string | array $mimetype) : voidMimetype to accept
Parameters| Name | Type | Description |
|---|
| $mimetype | string | array | MimeType |
|---|



_detectMimeType(string $file) : stringTry to detect mime type of given file.
Parameters| Name | Type | Description |
|---|
| $file | string | File which mime type should be detected |
|---|
Returns| Type | Description |
|---|
| string | File mime type or null if not detected |



_errorHandler(integer $errno, string $errstr, string $errfile, integer $errline) : voidSaves the provided error information by finfo_open to this instance
Parameters| Name | Type | Description |
|---|
| $errno | integer | |
|---|
| $errstr | string | |
|---|
| $errfile | string | |
|---|
| $errline | integer | |
|---|



_throw(string $file, string $errorType) : falseThrows an error of the given type
Parameters| Name | Type | Description |
|---|
| $file | string | |
|---|
| $errorType | string | |
|---|
Returns 


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


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


getMagicFile() : stringReturns 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


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



isValid(string $value, array $file = null) : booleanDefined 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.
Parameters| Name | Type | Description |
|---|
| $value | string | Real file to check for mimetype |
|---|
| $file | array | File data from Zend_File_Transfer |
|---|
Returns


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


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


setTryCommonMagicFilesFlag(boolean $flag = true) : \Zend_Validate_File_MimeTypeEnables or disables attempts to try the common magic file locations
specified by Zend_Validate_File_MimeType::_magicFiles
Parameters| Name | Type | Description |
|---|
| $flag | boolean | |
|---|
ReturnsDetails- See
-