Definition at line 35 of file MimeType.php.
◆ __construct()
Sets validator options
Mimetype to accept
- Parameters
-
string | array | $mimetype | MimeType |
- Exceptions
-
Definition at line 132 of file MimeType.php.
135 $mimetype = $mimetype->toArray();
136 }
elseif (is_string($mimetype)) {
137 $mimetype = explode(
',', $mimetype);
138 }
elseif (!is_array($mimetype)) {
139 #require_once 'Zend/Validate/Exception.php'; 143 if (isset($mimetype[
'magicfile'])) {
145 unset($mimetype[
'magicfile']);
148 if (isset($mimetype[
'headerCheck'])) {
150 unset($mimetype[
'headerCheck']);
elseif(isset( $params[ 'redirect_parent']))
enableHeaderCheck($headerCheck=true)
◆ _detectMimeType()
Try to detect mime type of given file.
- Parameters
-
string | $file | File which mime type should be detected |
- Returns
- string File mime type or null if not detected
Definition at line 431 of file MimeType.php.
437 $const = defined(
'FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME;
439 if (!empty($mimefile) && empty($this->_finfo)) {
440 set_error_handler(array($this,
'_errorHandler'), E_NOTICE | E_WARNING);
441 $this->_finfo = finfo_open($const, $mimefile);
442 restore_error_handler();
445 if (empty($this->_finfo)) {
446 set_error_handler(array($this,
'_errorHandler'), E_NOTICE | E_WARNING);
447 $this->_finfo = finfo_open($const);
448 restore_error_handler();
451 if (!empty($this->_finfo)) {
452 $type = finfo_file($this->_finfo, $file);
◆ _errorHandler()
_errorHandler |
( |
|
$errno, |
|
|
|
$errstr, |
|
|
|
$errfile, |
|
|
|
$errline |
|
) |
| |
|
protected |
Saves the provided error information by finfo_open to this instance
- Parameters
-
integer | $errno | |
string | $errstr | |
string | $errfile | |
integer | $errline | |
Definition at line 472 of file MimeType.php.
474 $this->_finfoError =
new ErrorException($errstr, $errno, 0, $errfile, $errline);
◆ _throw()
_throw |
( |
|
$file, |
|
|
|
$errorType |
|
) |
| |
|
protected |
Throws an error of the given type
- Parameters
-
string | $file | |
string | $errorType | |
- Returns
- false
Definition at line 419 of file MimeType.php.
421 $this->_value = $file[
'name'];
422 $this->
_error($errorType);
_error($messageKey, $value=null)
◆ addMimeType()
Adds the mimetypes
- Parameters
-
string | array | $mimetype | The mimetypes to add for validation |
- Exceptions
-
- Returns
- Zend_Validate_File_Extension Provides a fluent interface
Definition at line 324 of file MimeType.php.
328 if (is_string($mimetype)) {
329 $mimetype = explode(
',', $mimetype);
330 }
elseif (!is_array($mimetype)) {
331 #require_once 'Zend/Validate/Exception.php'; 335 if (isset($mimetype[
'magicfile'])) {
336 unset($mimetype[
'magicfile']);
345 $mimetypes = array_unique($mimetypes);
348 foreach ($mimetypes as $key => $mt) {
350 unset($mimetypes[$key]);
354 $this->_mimetype = implode(
',', $mimetypes);
elseif(isset( $params[ 'redirect_parent']))
getMimeType($asArray=false)
◆ enableHeaderCheck()
enableHeaderCheck |
( |
|
$headerCheck = true | ) |
|
Defines if the http header should be used Note that this is unsave and therefor the default value is false
- Parameters
-
- Returns
- Zend_Validate_File_MimeType Provides a fluent interface
Definition at line 281 of file MimeType.php.
283 $this->_headerCheck = (boolean) $headerCheck;
◆ getHeaderCheck()
Returns the Header Check option
- Returns
- boolean
Definition at line 269 of file MimeType.php.
◆ getMagicFile()
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
- string
Definition at line 165 of file MimeType.php.
167 if (version_compare(PHP_VERSION,
'5.3.0',
'<')
168 &&
null === $this->_magicfile) {
169 if (!empty($_ENV[
'MAGIC'])) {
175 #require_once 'Zend/Validate/Exception.php'; 176 foreach ($this->_magicFiles as $file) {
180 if ($this->_magicfile !==
null) {
189 if ($this->_magicfile ===
null) {
190 $this->_magicfile =
false;
elseif(isset( $params[ 'redirect_parent']))
shouldTryCommonMagicFiles()
◆ getMimeType()
getMimeType |
( |
|
$asArray = false | ) |
|
Returns the set mimetypes
- Parameters
-
boolean | $asArray | Returns the values as array, when false an concated string is returned |
- Returns
- string|array
Definition at line 293 of file MimeType.php.
295 $asArray = (bool) $asArray;
296 $mimetype = (string) $this->_mimetype;
298 $mimetype = explode(
',', $mimetype);
◆ isValid()
isValid |
( |
|
$value, |
|
|
|
$file = null |
|
) |
| |
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
-
- Returns
- boolean
Definition at line 370 of file MimeType.php.
372 if ($file ===
null) {
380 #require_once 'Zend/Loader.php'; 382 return $this->
_throw($file, self::NOT_READABLE);
387 if (empty($this->_type) && $this->_headerCheck) {
388 $this->_type = $file[
'type'];
391 if (empty($this->_type)) {
392 return $this->
_throw($file, self::NOT_DETECTED);
396 if (in_array($this->_type, $mimetype)) {
400 $types = explode(
'/', $this->_type);
401 $types = array_merge($types, explode(
'-', $this->_type));
402 $types = array_merge($types, explode(
';', $this->_type));
403 foreach($mimetype as $mime) {
404 if (in_array($mime, $types)) {
409 return $this->
_throw($file, self::FALSE_TYPE);
_throw($file, $errorType)
static isReadable($filename)
getMimeType($asArray=false)
◆ setMagicFile()
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
-
- Exceptions
-
- Returns
- Zend_Validate_File_MimeType Provides a fluent interface
Definition at line 206 of file MimeType.php.
209 $this->_magicfile =
null;
211 $this->_magicfile =
null;
212 #require_once 'Zend/Validate/Exception.php'; 215 #require_once 'Zend/Validate/Exception.php'; 218 $const = defined(
'FILEINFO_MIME_TYPE') ? FILEINFO_MIME_TYPE : FILEINFO_MIME;
219 set_error_handler(array($this,
'_errorHandler'), E_NOTICE | E_WARNING);
220 $this->_finfo = finfo_open($const, $file);
221 restore_error_handler();
222 if (empty($this->_finfo)) {
223 $this->_finfo =
null;
224 #require_once 'Zend/Validate/Exception.php'; 226 sprintf(
'The given magicfile ("%s") is not accepted by finfo', $file),
231 $this->_magicfile = $file;
◆ setMimeType()
Sets the mimetypes
- Parameters
-
string | array | $mimetype | The mimetypes to validate |
- Returns
- Zend_Validate_File_Extension Provides a fluent interface
Definition at line 310 of file MimeType.php.
312 $this->_mimetype =
null;
◆ setTryCommonMagicFilesFlag()
setTryCommonMagicFilesFlag |
( |
|
$flag = true | ) |
|
◆ shouldTryCommonMagicFiles()
shouldTryCommonMagicFiles |
( |
| ) |
|
◆ $_finfo
◆ $_finfoError
◆ $_headerCheck
◆ $_magicfile
◆ $_magicFiles
Initial value:= 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',
)
Definition at line 92 of file MimeType.php.
◆ $_messageTemplates
Initial value:= 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",
)
Definition at line 47 of file MimeType.php.
◆ $_messageVariables
Initial value:= array(
'type' => '_type'
)
Definition at line 56 of file MimeType.php.
◆ $_mimetype
◆ $_tryCommonMagicFiles
$_tryCommonMagicFiles = true |
|
protected |
◆ $_type
◆ FALSE_TYPE
const FALSE_TYPE = 'fileMimeTypeFalse' |
@const Error type constants
Definition at line 40 of file MimeType.php.
◆ NOT_DETECTED
const NOT_DETECTED = 'fileMimeTypeNotDetected' |
◆ NOT_READABLE
const NOT_READABLE = 'fileMimeTypeNotReadable' |
The documentation for this class was generated from the following file:
- vendor/magento/zendframework1/library/Zend/Validate/File/MimeType.php