Validate/File/MimeType.php

Show: PublicProtectedPrivateinherited
Table of Contents
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_Validate
Validator 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

>VConstant  FALSE_TYPE = 'fileMimeTypeFalse'
Const
Error type constants  
>VConstant  NOT_DETECTED = 'fileMimeTypeNotDetected'
>VConstant  NOT_READABLE = 'fileMimeTypeNotReadable'

Properties

>VPropertyprotectedresource $_finfo
Finfo object to use
Details
Type
resource
>VPropertyprotectedarray $_finfoError
Holds error information returned by finfo_open
Details
Type
array
>VPropertyprotectedboolean $_headerCheck = false
Option to allow header check
Default valuefalseDetails
Type
boolean
>VPropertyprotectedarray $_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
>VPropertyprotectedstring|null $_magicfile
Magicfile to use
Details
Type
string | null
>VPropertyprotectedarray $_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")

Error message templates

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
>VPropertyprotectedarray $_messageVariables = array('type' => '_type')
Default valuearray('type' => '_type')Details
Type
array
>VPropertyprotectedstring|null $_mimetype
Mimetypes
If null, there is no mimetype
Details
Type
string | null
>VPropertyprotectedboolean $_tryCommonMagicFiles = true
Indicates whether use of $_magicFiles should be attempted.
Default valuetrueDetails
Type
boolean
>VPropertyprotectedstring $_type
Details
Type
string

Methods

methodpublic__construct(string | array $mimetype) : void

Sets validator options

Mimetype to accept
Parameters
NameTypeDescription
$mimetypestring | array

MimeType

methodprotected_detectMimeType(string $file) : string

Try to detect mime type of given file.

Parameters
NameTypeDescription
$filestring

File which mime type should be detected

Returns
TypeDescription
stringFile mime type or null if not detected
methodprotected_errorHandler(integer $errno, string $errstr, string $errfile, integer $errline) : void

Saves the provided error information by finfo_open to this instance

Parameters
NameTypeDescription
$errnointeger
$errstrstring
$errfilestring
$errlineinteger
methodprotected_throw(string $file, string $errorType) : false

Throws an error of the given type

Parameters
NameTypeDescription
$filestring
$errorTypestring
Returns
TypeDescription
false
methodpublicaddMimeType(string | array $mimetype) : \Zend_Validate_File_Extension

Adds the mimetypes

Parameters
NameTypeDescription
$mimetypestring | array

The mimetypes to add for validation

Returns
TypeDescription
\Zend_Validate_File_ExtensionProvides a fluent interface
methodpublicenableHeaderCheck( $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

Parameters
NameTypeDescription
$headerCheck
Returns
TypeDescription
\Zend_Validate_File_MimeTypeProvides fluid interface
methodpublicgetHeaderCheck() : boolean

Returns the Header Check option

Returns
TypeDescription
boolean
methodpublicgetMagicFile() : 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
TypeDescription
string
methodpublicgetMimeType(boolean $asArray = false) : string | array

Returns the set mimetypes

Parameters
NameTypeDescription
$asArrayboolean

Returns the values as array, when false an concated string is returned

Returns
TypeDescription
string | array
methodpublicisValid(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.
Parameters
NameTypeDescription
$valuestring

Real file to check for mimetype

$filearray

File data from Zend_File_Transfer

Returns
TypeDescription
boolean
methodpublicsetMagicFile(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

Parameters
NameTypeDescription
$filestring
Returns
TypeDescription
\Zend_Validate_File_MimeTypeProvides fluid interface
Throws
ExceptionDescription
\Zend_Validate_ExceptionWhen finfo can not read the magicfile
methodpublicsetMimeType(string | array $mimetype) : \Zend_Validate_File_Extension

Sets the mimetypes

Parameters
NameTypeDescription
$mimetypestring | array

The mimetypes to validate

Returns
TypeDescription
\Zend_Validate_File_ExtensionProvides a fluent interface
methodpublicsetTryCommonMagicFilesFlag(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

Parameters
NameTypeDescription
$flagboolean
Returns
TypeDescription
\Zend_Validate_File_MimeTypeProvides fluent interface
Details
See
 
methodpublicshouldTryCommonMagicFiles() : boolean

Accessor for Zend_Validate_File_MimeType::_magicFiles

Returns
TypeDescription
boolean
Details
See
 
Documentation was generated by phpDocumentor 2.2.0 .