import v1.1.0_beta1 | 2009-08-21

This commit is contained in:
2019-07-17 22:16:19 +02:00
parent 2c1152f0d3
commit 8dee6b1a10
2306 changed files with 251360 additions and 23428 deletions

View File

@ -119,7 +119,7 @@ class Zend_Validate_File_Upload extends Zend_Validate_Abstract
}
/**
* Sets the minimum filesize
* Sets the files to be checked
*
* @param array $files The files to check in syntax of Zend_File_Transfer
* @return Zend_Validate_File_Upload Provides a fluent interface
@ -131,6 +131,13 @@ class Zend_Validate_File_Upload extends Zend_Validate_Abstract
} else {
$this->_files = $files;
}
foreach($this->_files as $file => $content) {
if (!isset($content['error'])) {
unset($this->_files[$file]);
}
}
return $this;
}
@ -143,25 +150,24 @@ class Zend_Validate_File_Upload extends Zend_Validate_Abstract
* from initialization will be used
* @return boolean
*/
public function isValid($value)
public function isValid($value, $file = null)
{
if (array_key_exists($value, $this->_files)) {
$files[$value] = $this->_files[$value];
} else {
foreach ($this->_files as $file => $content) {
if ($content['name'] === $value) {
if (isset($content['name']) && ($content['name'] === $value)) {
$files[$file] = $this->_files[$file];
}
if ($content['tmp_name'] === $value) {
if (isset($content['tmp_name']) && ($content['tmp_name'] === $value)) {
$files[$file] = $this->_files[$file];
}
}
}
if (empty($files)) {
$this->_error(self::FILE_NOT_FOUND);
return false;
return $this->_throw($file, self::FILE_NOT_FOUND);
}
foreach ($files as $file => $content) {
@ -169,40 +175,40 @@ class Zend_Validate_File_Upload extends Zend_Validate_Abstract
switch($content['error']) {
case 0:
if (!is_uploaded_file($content['tmp_name'])) {
$this->_error(self::ATTACK);
$this->_throw($file, self::ATTACK);
}
break;
case 1:
$this->_error(self::INI_SIZE);
$this->_throw($file, self::INI_SIZE);
break;
case 2:
$this->_error(self::FORM_SIZE);
$this->_throw($file, self::FORM_SIZE);
break;
case 3:
$this->_error(self::PARTIAL);
$this->_throw($file, self::PARTIAL);
break;
case 4:
$this->_error(self::NO_FILE);
$this->_throw($file, self::NO_FILE);
break;
case 6:
$this->_error(self::NO_TMP_DIR);
$this->_throw($file, self::NO_TMP_DIR);
break;
case 7:
$this->_error(self::CANT_WRITE);
$this->_throw($file, self::CANT_WRITE);
break;
case 8:
$this->_error(self::EXTENSION);
$this->_throw($file, self::EXTENSION);
break;
default:
$this->_error(self::UNKNOWN);
$this->_throw($file, self::UNKNOWN);
break;
}
}
@ -213,4 +219,23 @@ class Zend_Validate_File_Upload extends Zend_Validate_Abstract
return true;
}
}
/**
* Throws an error of the given type
*
* @param string $file
* @param string $errorType
* @return false
*/
protected function _throw($file, $errorType)
{
if ($file !== null) {
if (is_array($file) and !empty($file['name'])) {
$this->_value = $file['name'];
}
}
$this->_error($errorType);
return false;
}
}