7
* This source file is subject to the new BSD license that is bundled
8
* with this package in the file LICENSE.txt.
9
* It is also available through the world-wide-web at this URL:
10
* http://framework.zend.com/license/new-bsd
11
* If you did not receive a copy of the license and are unable to
12
* obtain it through the world-wide-web, please send an email
13
* to license@zend.com so we can send you a copy immediately.
16
* @package Zend_Validate
17
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
18
* @license http://framework.zend.com/license/new-bsd New BSD License
23
* @see Zend_Validate_File_MimeType
25
require_once 'Zend/Validate/File/MimeType.php';
28
* Validator for the mime type of a file
31
* @package Zend_Validate
32
* @copyright Copyright (c) 2005-2008 Zend Technologies USA Inc. (http://www.zend.com)
33
* @license http://framework.zend.com/license/new-bsd New BSD License
35
class Zend_Validate_File_ExcludeMimeType extends Zend_Validate_File_MimeType
37
const FALSE_TYPE = 'fileExcludeMimeTypeFalse';
38
const NOT_DETECTED = 'fileExcludeMimeTypeNotDetected';
39
const NOT_READABLE = 'fileExcludeMimeTypeNotReadable';
42
* Defined by Zend_Validate_Interface
44
* Returns true if the mimetype of the file does not matche the given ones. Also parts
45
* of mimetypes can be checked. If you give for example "image" all image
46
* mime types will not be accepted like "image/gif", "image/jpeg" and so on.
48
* @param string $value Real file to check for mimetype
49
* @param array $file File data from Zend_File_Transfer
52
public function isValid($value, $file = null)
55
require_once 'Zend/Loader.php';
56
if (!Zend_Loader::isReadable($value)) {
57
return $this->_throw($file, self::NOT_READABLE);
61
if (class_exists('finfo', false) && defined('MAGIC')) {
62
$mime = new finfo(FILEINFO_MIME);
63
$this->_type = $mime->file($value);
65
} elseif (function_exists('mime_content_type') && ini_get('mime_magic.magicfile')) {
66
$this->_type = mime_content_type($value);
68
$this->_type = $file['type'];
72
if (empty($this->_type)) {
73
return $this->_throw($file, self::NOT_DETECTED);
76
$mimetype = $this->getMimeType(true);
77
if (in_array($this->_type, $mimetype)) {
78
return $this->_throw($file, self::FALSE_TYPE);
81
$types = explode('/', $this->_type);
82
$types = array_merge($types, explode('-', $this->_type));
83
foreach($mimetype as $mime) {
84
if (in_array($mime, $types)) {
85
return $this->_throw($file, self::FALSE_TYPE);