25 #require_once 'Zend/Validate/Abstract.php'; 48 self::FALSE_TYPE =>
"File '%value%' has a false mimetype of '%type%'",
49 self::NOT_DETECTED =>
"The mimetype of file '%value%' could not be detected",
50 self::NOT_READABLE =>
"File '%value%' is not readable or does not exist",
93 '/usr/share/misc/magic',
94 '/usr/share/misc/magic.mime',
95 '/usr/share/misc/magic.mgc',
96 '/usr/share/mime/magic',
97 '/usr/share/mime/magic.mime',
98 '/usr/share/mime/magic.mgc',
99 '/usr/share/file/magic',
100 '/usr/share/file/magic.mime',
101 '/usr/share/file/magic.mgc',
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']);
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;
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;
248 $this->_tryCommonMagicFiles = (boolean) $flag;
283 $this->_headerCheck = (boolean) $headerCheck;
295 $asArray = (bool) $asArray;
296 $mimetype = (string) $this->_mimetype;
298 $mimetype = explode(
',', $mimetype);
312 $this->_mimetype =
null;
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);
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);
419 protected function _throw($file, $errorType)
421 $this->_value = $file[
'name'];
422 $this->
_error($errorType);
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);
474 $this->_finfoError =
new ErrorException($errstr, $errno, 0, $errfile, $errline);
elseif(isset( $params[ 'redirect_parent']))
enableHeaderCheck($headerCheck=true)
setTryCommonMagicFilesFlag($flag=true)
_throw($file, $errorType)
_error($messageKey, $value=null)
isValid($value, $file=null)
static isReadable($filename)
_errorHandler($errno, $errstr, $errfile, $errline)
shouldTryCommonMagicFiles()
getMimeType($asArray=false)