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 = 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
boolean $_tryCommonMagicFiles = true
Indicates whether use of $_magicFiles should be attempted.
Default valuetrue
Details- Type
- boolean
Methods
__construct(string | array $mimetype) : void
Mimetype to accept
ParametersName | Type | Description |
---|
$mimetype | string | array | MimeType |
---|
_detectMimeType(string $file) : string
Try to detect mime type of given file.
ParametersName | Type | Description |
---|
$file | string | File which mime type should be detected |
---|
ReturnsType | Description |
---|
string | File mime type or null if not detected |
_errorHandler(integer $errno, string $errstr, string $errfile, integer $errline) : void
Saves the provided error information by finfo_open to this instance
ParametersName | Type | Description |
---|
$errno | integer | |
---|
$errstr | string | |
---|
$errfile | string | |
---|
$errline | integer | |
---|
_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.
ReturnsgetMimeType(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 |
---|
ReturnssetMagicFile(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 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
-