web/lib/Zend/Validate/File/Upload.php
changeset 807 877f952ae2bd
parent 207 621fa6caec0c
child 1230 68c69c656a2c
equal deleted inserted replaced
805:5e7a0fedabdf 807:877f952ae2bd
    12  * obtain it through the world-wide-web, please send an email
    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.
    13  * to license@zend.com so we can send you a copy immediately.
    14  *
    14  *
    15  * @category  Zend
    15  * @category  Zend
    16  * @package   Zend_Validate
    16  * @package   Zend_Validate
    17  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    17  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    18  * @license   http://framework.zend.com/license/new-bsd     New BSD License
    18  * @license   http://framework.zend.com/license/new-bsd     New BSD License
    19  * @version   $Id: Upload.php 22398 2010-06-09 19:05:46Z thomas $
    19  * @version   $Id: Upload.php 24959 2012-06-15 13:51:04Z adamlundrigan $
    20  */
    20  */
    21 
    21 
    22 /**
    22 /**
    23  * @see Zend_Validate_Abstract
    23  * @see Zend_Validate_Abstract
    24  */
    24  */
    27 /**
    27 /**
    28  * Validator for the maximum size of a file up to a max of 2GB
    28  * Validator for the maximum size of a file up to a max of 2GB
    29  *
    29  *
    30  * @category  Zend
    30  * @category  Zend
    31  * @package   Zend_Validate
    31  * @package   Zend_Validate
    32  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
    32  * @copyright  Copyright (c) 2005-2012 Zend Technologies USA Inc. (http://www.zend.com)
    33  * @license   http://framework.zend.com/license/new-bsd     New BSD License
    33  * @license   http://framework.zend.com/license/new-bsd     New BSD License
    34  */
    34  */
    35 class Zend_Validate_File_Upload extends Zend_Validate_Abstract
    35 class Zend_Validate_File_Upload extends Zend_Validate_Abstract
    36 {
    36 {
    37     /**@#+
    37     /**@#+
   134             $this->_files = $_FILES;
   134             $this->_files = $_FILES;
   135         } else {
   135         } else {
   136             $this->_files = $files;
   136             $this->_files = $files;
   137         }
   137         }
   138 
   138 
       
   139         // see ZF-10738
       
   140         if (is_null($this->_files)) {
       
   141             $this->_files = array();
       
   142         }
       
   143 
   139         foreach($this->_files as $file => $content) {
   144         foreach($this->_files as $file => $content) {
   140             if (!isset($content['error'])) {
   145             if (!isset($content['error'])) {
   141                 unset($this->_files[$file]);
   146                 unset($this->_files[$file]);
   142             }
   147             }
   143         }
   148         }
   178         foreach ($files as $file => $content) {
   183         foreach ($files as $file => $content) {
   179             $this->_value = $file;
   184             $this->_value = $file;
   180             switch($content['error']) {
   185             switch($content['error']) {
   181                 case 0:
   186                 case 0:
   182                     if (!is_uploaded_file($content['tmp_name'])) {
   187                     if (!is_uploaded_file($content['tmp_name'])) {
   183                         $this->_throw($file, self::ATTACK);
   188                         $this->_throw($content, self::ATTACK);
   184                     }
   189                     }
   185                     break;
   190                     break;
   186 
   191 
   187                 case 1:
   192                 case 1:
   188                     $this->_throw($file, self::INI_SIZE);
   193                     $this->_throw($content, self::INI_SIZE);
   189                     break;
   194                     break;
   190 
   195 
   191                 case 2:
   196                 case 2:
   192                     $this->_throw($file, self::FORM_SIZE);
   197                     $this->_throw($content, self::FORM_SIZE);
   193                     break;
   198                     break;
   194 
   199 
   195                 case 3:
   200                 case 3:
   196                     $this->_throw($file, self::PARTIAL);
   201                     $this->_throw($content, self::PARTIAL);
   197                     break;
   202                     break;
   198 
   203 
   199                 case 4:
   204                 case 4:
   200                     $this->_throw($file, self::NO_FILE);
   205                     $this->_throw($content, self::NO_FILE);
   201                     break;
   206                     break;
   202 
   207 
   203                 case 6:
   208                 case 6:
   204                     $this->_throw($file, self::NO_TMP_DIR);
   209                     $this->_throw($content, self::NO_TMP_DIR);
   205                     break;
   210                     break;
   206 
   211 
   207                 case 7:
   212                 case 7:
   208                     $this->_throw($file, self::CANT_WRITE);
   213                     $this->_throw($content, self::CANT_WRITE);
   209                     break;
   214                     break;
   210 
   215 
   211                 case 8:
   216                 case 8:
   212                     $this->_throw($file, self::EXTENSION);
   217                     $this->_throw($content, self::EXTENSION);
   213                     break;
   218                     break;
   214 
   219 
   215                 default:
   220                 default:
   216                     $this->_throw($file, self::UNKNOWN);
   221                     $this->_throw($content, self::UNKNOWN);
   217                     break;
   222                     break;
   218             }
   223             }
   219         }
   224         }
   220 
   225 
   221         if (count($this->_messages) > 0) {
   226         if (count($this->_messages) > 0) {