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-2010 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 which checks if the file already exists in the directory
31 * @package Zend_Validate
32 * @copyright Copyright (c) 2005-2010 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_IsImage
extends Zend_Validate_File_MimeType
38 * @const string Error constants
40 const FALSE_TYPE
= 'fileIsImageFalseType';
41 const NOT_DETECTED
= 'fileIsImageNotDetected';
42 const NOT_READABLE
= 'fileIsImageNotReadable';
45 * @var array Error message templates
47 protected $_messageTemplates = array(
48 self
::FALSE_TYPE
=> "File '%value%' is no image, '%type%' detected",
49 self
::NOT_DETECTED
=> "The mimetype of file '%value%' could not be detected",
50 self
::NOT_READABLE
=> "File '%value%' can not be read",
54 * Sets validator options
56 * @param string|array|Zend_Config $mimetype
59 public function __construct($mimetype = array())
61 if ($mimetype instanceof Zend_Config
) {
62 $mimetype = $mimetype->toArray();
66 // http://de.wikipedia.org/wiki/Liste_von_Dateiendungen
67 // http://www.iana.org/assignments/media-types/image/
71 'application/fractals',
72 'application/postscript',
73 'application/vnd.hp-hpgl',
74 'application/vnd.oasis.opendocument.graphics',
76 'application/x-cmu-raster',
78 'application/x-inventor',
80 'application/x-portable-anymap',
81 'application/x-world-x-3dmf',
97 'image/vnd.adobe.photoshop',
101 'image/x-cmu-raster',
113 'image/x-portable-anymap',
114 'image/x-portable-bitmap',
115 'image/x-portable-greymap',
116 'image/x-portable-pixmap',
121 'image/x-windows-bmp',
125 if (is_array($mimetype)) {
127 if (array_key_exists('magicfile', $temp)) {
128 unset($temp['magicfile']);
131 if (array_key_exists('headerCheck', $temp)) {
132 unset($temp['headerCheck']);
136 $mimetype +
= $default;
140 if (empty($mimetype)) {
141 $mimetype = $default;
144 parent
::__construct($mimetype);
148 * Throws an error of the given type
149 * Duplicates parent method due to OOP Problem with late static binding in PHP 5.2
151 * @param string $file
152 * @param string $errorType
155 protected function _throw($file, $errorType)
157 $this->_value
= $file['name'];
159 case Zend_Validate_File_MimeType
::FALSE_TYPE
:
160 $errorType = self
::FALSE_TYPE
;
162 case Zend_Validate_File_MimeType
::NOT_DETECTED
:
163 $errorType = self
::NOT_DETECTED
;
165 case Zend_Validate_File_MimeType
::NOT_READABLE
:
166 $errorType = self
::NOT_READABLE
;
170 $this->_error($errorType);