File indexing completed on 2025-01-19 05:21:38
0001 <?php 0002 /** 0003 * Zend Framework 0004 * 0005 * LICENSE 0006 * 0007 * This source file is subject to the new BSD license that is bundled 0008 * with this package in the file LICENSE.txt. 0009 * It is also available through the world-wide-web at this URL: 0010 * http://framework.zend.com/license/new-bsd 0011 * If you did not receive a copy of the license and are unable to 0012 * obtain it through the world-wide-web, please send an email 0013 * to license@zend.com so we can send you a copy immediately. 0014 * 0015 * @category Zend 0016 * @package Zend_Validate 0017 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0018 * @license http://framework.zend.com/license/new-bsd New BSD License 0019 * @version $Id$ 0020 */ 0021 0022 /** 0023 * @see Zend_Validate_File_MimeType 0024 */ 0025 // require_once 'Zend/Validate/File/MimeType.php'; 0026 0027 /** 0028 * Validator which checks if the file already exists in the directory 0029 * 0030 * @category Zend 0031 * @package Zend_Validate 0032 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0033 * @license http://framework.zend.com/license/new-bsd New BSD License 0034 */ 0035 class Zend_Validate_File_IsImage extends Zend_Validate_File_MimeType 0036 { 0037 /** 0038 * @const string Error constants 0039 */ 0040 const FALSE_TYPE = 'fileIsImageFalseType'; 0041 const NOT_DETECTED = 'fileIsImageNotDetected'; 0042 const NOT_READABLE = 'fileIsImageNotReadable'; 0043 0044 /** 0045 * @var array Error message templates 0046 */ 0047 protected $_messageTemplates = array( 0048 self::FALSE_TYPE => "File '%value%' is no image, '%type%' detected", 0049 self::NOT_DETECTED => "The mimetype of file '%value%' could not be detected", 0050 self::NOT_READABLE => "File '%value%' is not readable or does not exist", 0051 ); 0052 0053 /** 0054 * Sets validator options 0055 * 0056 * @param string|array|Zend_Config $mimetype 0057 */ 0058 public function __construct($mimetype = array()) 0059 { 0060 if ($mimetype instanceof Zend_Config) { 0061 $mimetype = $mimetype->toArray(); 0062 } 0063 0064 $temp = array(); 0065 // http://de.wikipedia.org/wiki/Liste_von_Dateiendungen 0066 // http://www.iana.org/assignments/media-types/image/ 0067 $default = array( 0068 'application/cdf', 0069 'application/dicom', 0070 'application/fractals', 0071 'application/postscript', 0072 'application/vnd.hp-hpgl', 0073 'application/vnd.oasis.opendocument.graphics', 0074 'application/x-cdf', 0075 'application/x-cmu-raster', 0076 'application/x-ima', 0077 'application/x-inventor', 0078 'application/x-koan', 0079 'application/x-portable-anymap', 0080 'application/x-world-x-3dmf', 0081 'image/bmp', 0082 'image/c', 0083 'image/cgm', 0084 'image/fif', 0085 'image/gif', 0086 'image/jpeg', 0087 'image/jpm', 0088 'image/jpx', 0089 'image/jp2', 0090 'image/naplps', 0091 'image/pjpeg', 0092 'image/png', 0093 'image/svg', 0094 'image/svg+xml', 0095 'image/tiff', 0096 'image/vnd.adobe.photoshop', 0097 'image/vnd.djvu', 0098 'image/vnd.fpx', 0099 'image/vnd.net-fpx', 0100 'image/x-cmu-raster', 0101 'image/x-cmx', 0102 'image/x-coreldraw', 0103 'image/x-cpi', 0104 'image/x-emf', 0105 'image/x-ico', 0106 'image/x-icon', 0107 'image/x-jg', 0108 'image/x-ms-bmp', 0109 'image/x-niff', 0110 'image/x-pict', 0111 'image/x-pcx', 0112 'image/x-portable-anymap', 0113 'image/x-portable-bitmap', 0114 'image/x-portable-greymap', 0115 'image/x-portable-pixmap', 0116 'image/x-quicktime', 0117 'image/x-rgb', 0118 'image/x-tiff', 0119 'image/x-unknown', 0120 'image/x-windows-bmp', 0121 'image/x-xpmi', 0122 ); 0123 0124 if (is_array($mimetype)) { 0125 $temp = $mimetype; 0126 if (array_key_exists('magicfile', $temp)) { 0127 unset($temp['magicfile']); 0128 } 0129 0130 if (array_key_exists('headerCheck', $temp)) { 0131 unset($temp['headerCheck']); 0132 } 0133 0134 if (empty($temp)) { 0135 $mimetype += $default; 0136 } 0137 } 0138 0139 if (empty($mimetype)) { 0140 $mimetype = $default; 0141 } 0142 0143 parent::__construct($mimetype); 0144 } 0145 0146 /** 0147 * Throws an error of the given type 0148 * Duplicates parent method due to OOP Problem with late static binding in PHP 5.2 0149 * 0150 * @param string $file 0151 * @param string $errorType 0152 * @return false 0153 */ 0154 protected function _throw($file, $errorType) 0155 { 0156 $this->_value = $file['name']; 0157 switch($errorType) { 0158 case Zend_Validate_File_MimeType::FALSE_TYPE : 0159 $errorType = self::FALSE_TYPE; 0160 break; 0161 case Zend_Validate_File_MimeType::NOT_DETECTED : 0162 $errorType = self::NOT_DETECTED; 0163 break; 0164 case Zend_Validate_File_MimeType::NOT_READABLE : 0165 $errorType = self::NOT_READABLE; 0166 break; 0167 } 0168 0169 $this->_error($errorType); 0170 return false; 0171 } 0172 }