Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes
Zend_Validate_File_Upload Class Reference
Inheritance diagram for Zend_Validate_File_Upload:
Zend_Validate_Abstract Zend_Validate_Interface

Public Member Functions

 __construct ($files=array())
 
 getFiles ($file=null)
 
 setFiles ($files=array())
 
 isValid ($value, $file=null)
 
- Public Member Functions inherited from Zend_Validate_Abstract
 getMessages ()
 
 getMessageVariables ()
 
 getMessageTemplates ()
 
 setMessage ($messageString, $messageKey=null)
 
 setMessages (array $messages)
 
 __get ($property)
 
 getErrors ()
 
 setObscureValue ($flag)
 
 getObscureValue ()
 
 setTranslator ($translator=null)
 
 getTranslator ()
 
 hasTranslator ()
 
 setDisableTranslator ($flag)
 
 translatorIsDisabled ()
 
- Public Member Functions inherited from Zend_Validate_Interface
 isValid ($value)
 

Data Fields

const INI_SIZE = 'fileUploadErrorIniSize'
 
const FORM_SIZE = 'fileUploadErrorFormSize'
 
const PARTIAL = 'fileUploadErrorPartial'
 
const NO_FILE = 'fileUploadErrorNoFile'
 
const NO_TMP_DIR = 'fileUploadErrorNoTmpDir'
 
const CANT_WRITE = 'fileUploadErrorCantWrite'
 
const EXTENSION = 'fileUploadErrorExtension'
 
const ATTACK = 'fileUploadErrorAttack'
 
const FILE_NOT_FOUND = 'fileUploadErrorFileNotFound'
 
const UNKNOWN = 'fileUploadErrorUnknown'
 

Protected Member Functions

 _throw ($file, $errorType)
 
- Protected Member Functions inherited from Zend_Validate_Abstract
 _createMessage ($messageKey, $value)
 
 _implodeRecursive (array $pieces)
 
 _error ($messageKey, $value=null)
 
 _setValue ($value)
 

Protected Attributes

 $_messageTemplates
 
 $_files = array()
 
- Protected Attributes inherited from Zend_Validate_Abstract
 $_value
 
 $_messageVariables = array()
 
 $_messageTemplates = array()
 
 $_messages = array()
 
 $_obscureValue = false
 
 $_errors = array()
 
 $_translator
 
 $_translatorDisabled = false
 

Additional Inherited Members

- Static Public Member Functions inherited from Zend_Validate_Abstract
static setDefaultTranslator ($translator=null)
 
static getDefaultTranslator ()
 
static hasDefaultTranslator ()
 
static getMessageLength ()
 
static setMessageLength ($length=-1)
 
- Static Protected Attributes inherited from Zend_Validate_Abstract
static $_defaultTranslator
 
static $_messageLength = -1
 

Detailed Description

Definition at line 35 of file Upload.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $files = array())

Sets validator options

The array $files must be given in syntax of Zend_File_Transfer to be checked If no files are given the $_FILES array will be used automatically. NOTE: This validator will only work with HTTP POST uploads!

Parameters
array | Zend_Config$filesArray of files in syntax of Zend_File_Transfer

Definition at line 83 of file Upload.php.

84  {
85  if ($files instanceof Zend_Config) {
86  $files = $files->toArray();
87  }
88 
89  $this->setFiles($files);
90  }
setFiles($files=array())
Definition: Upload.php:130
foreach($appDirs as $dir) $files

Member Function Documentation

◆ _throw()

_throw (   $file,
  $errorType 
)
protected

Throws an error of the given type

Parameters
string$file
string$errorType
Returns
false

Definition at line 236 of file Upload.php.

237  {
238  if ($file !== null) {
239  if (is_array($file) and !empty($file['name'])) {
240  $this->_value = $file['name'];
241  }
242  }
243 
244  $this->_error($errorType);
245  return false;
246  }
_error($messageKey, $value=null)
Definition: Abstract.php:284

◆ getFiles()

getFiles (   $file = null)

Returns the array of set files

Parameters
string$file(Optional) The file to return in detail
Returns
array
Exceptions
Zend_Validate_ExceptionIf file is not found

Definition at line 99 of file Upload.php.

100  {
101  if ($file !== null) {
102  $return = array();
103  foreach ($this->_files as $name => $content) {
104  if ($name === $file) {
105  $return[$file] = $this->_files[$name];
106  }
107 
108  if ($content['name'] === $file) {
109  $return[$name] = $this->_files[$name];
110  }
111  }
112 
113  if (count($return) === 0) {
114  #require_once 'Zend/Validate/Exception.php';
115  throw new Zend_Validate_Exception("The file '$file' was not found");
116  }
117 
118  return $return;
119  }
120 
121  return $this->_files;
122  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ isValid()

isValid (   $value,
  $file = null 
)

Defined by Zend_Validate_Interface

Returns true if and only if the file was uploaded without errors

Parameters
string$valueSingle file to check for upload errors, when giving null the $_FILES array from initialization will be used
string | null$file
Returns
boolean

Definition at line 162 of file Upload.php.

163  {
164  $this->_messages = [];
165  if (array_key_exists($value, $this->_files)) {
166  $files[$value] = $this->_files[$value];
167  } else {
168  foreach ($this->_files as $file => $content) {
169  if (isset($content['name']) && ($content['name'] === $value)) {
170  $files[$file] = $this->_files[$file];
171  }
172 
173  if (isset($content['tmp_name']) && ($content['tmp_name'] === $value)) {
174  $files[$file] = $this->_files[$file];
175  }
176  }
177  }
178 
179  if (empty($files)) {
180  return $this->_throw($file, self::FILE_NOT_FOUND);
181  }
182 
183  foreach ($files as $file => $content) {
184  $this->_value = $file;
185  switch($content['error']) {
186  case 0:
187  if (!is_uploaded_file($content['tmp_name'])) {
188  $this->_throw($content, self::ATTACK);
189  }
190  break;
191 
192  case 1:
193  $this->_throw($content, self::INI_SIZE);
194  break;
195 
196  case 2:
197  $this->_throw($content, self::FORM_SIZE);
198  break;
199 
200  case 3:
201  $this->_throw($content, self::PARTIAL);
202  break;
203 
204  case 4:
205  $this->_throw($content, self::NO_FILE);
206  break;
207 
208  case 6:
209  $this->_throw($content, self::NO_TMP_DIR);
210  break;
211 
212  case 7:
213  $this->_throw($content, self::CANT_WRITE);
214  break;
215 
216  case 8:
217  $this->_throw($content, self::EXTENSION);
218  break;
219 
220  default:
221  $this->_throw($content, self::UNKNOWN);
222  break;
223  }
224  }
225 
226  return empty($this->_messages);
227  }
$value
Definition: gender.phtml:16
_throw($file, $errorType)
Definition: Upload.php:236
foreach($appDirs as $dir) $files

◆ setFiles()

setFiles (   $files = array())

Sets the files to be checked

Parameters
array$filesThe files to check in syntax of Zend_File_Transfer
Returns
Zend_Validate_File_Upload Provides a fluent interface

Definition at line 130 of file Upload.php.

131  {
132  if (count($files) === 0) {
133  $this->_files = $_FILES;
134  } else {
135  $this->_files = $files;
136  }
137 
138  // see ZF-10738
139  if (is_null($this->_files)) {
140  $this->_files = array();
141  }
142 
143  foreach($this->_files as $file => $content) {
144  if (!isset($content['error'])) {
145  unset($this->_files[$file]);
146  }
147  }
148 
149  return $this;
150  }
foreach($appDirs as $dir) $files

Field Documentation

◆ $_files

$_files = array()
protected

Definition at line 72 of file Upload.php.

◆ $_messageTemplates

$_messageTemplates
protected
Initial value:
= array(
self::INI_SIZE => "File '%value%' exceeds the defined ini size",
self::FORM_SIZE => "File '%value%' exceeds the defined form size",
self::PARTIAL => "File '%value%' was only partially uploaded",
self::NO_FILE => "File '%value%' was not uploaded",
self::NO_TMP_DIR => "No temporary directory was found for file '%value%'",
self::CANT_WRITE => "File '%value%' can't be written",
self::EXTENSION => "A PHP extension returned an error while uploading the file '%value%'",
self::ATTACK => "File '%value%' was illegally uploaded. This could be a possible attack",
self::FILE_NOT_FOUND => "File '%value%' was not found",
self::UNKNOWN => "Unknown error while uploading file '%value%'"
)

Definition at line 55 of file Upload.php.

◆ ATTACK

const ATTACK = 'fileUploadErrorAttack'

Definition at line 47 of file Upload.php.

◆ CANT_WRITE

const CANT_WRITE = 'fileUploadErrorCantWrite'

Definition at line 45 of file Upload.php.

◆ EXTENSION

const EXTENSION = 'fileUploadErrorExtension'

Definition at line 46 of file Upload.php.

◆ FILE_NOT_FOUND

const FILE_NOT_FOUND = 'fileUploadErrorFileNotFound'

Definition at line 48 of file Upload.php.

◆ FORM_SIZE

const FORM_SIZE = 'fileUploadErrorFormSize'

Definition at line 41 of file Upload.php.

◆ INI_SIZE

const INI_SIZE = 'fileUploadErrorIniSize'

#+ @const string Error constants

Definition at line 40 of file Upload.php.

◆ NO_FILE

const NO_FILE = 'fileUploadErrorNoFile'

Definition at line 43 of file Upload.php.

◆ NO_TMP_DIR

const NO_TMP_DIR = 'fileUploadErrorNoTmpDir'

Definition at line 44 of file Upload.php.

◆ PARTIAL

const PARTIAL = 'fileUploadErrorPartial'

Definition at line 42 of file Upload.php.

◆ UNKNOWN

const UNKNOWN = 'fileUploadErrorUnknown'

Definition at line 49 of file Upload.php.


The documentation for this class was generated from the following file: