Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Static Public Member Functions | Protected Member Functions | Static Protected Attributes
Zend_File_Transfer_Adapter_Http Class Reference
Inheritance diagram for Zend_File_Transfer_Adapter_Http:
Zend_File_Transfer_Adapter_Abstract

Public Member Functions

 __construct ($options=array())
 
 setValidators (array $validators, $files=null)
 
 removeValidator ($name)
 
 clearValidators ()
 
 send ($options=null)
 
 isValid ($files=null)
 
 receive ($files=null)
 
 isSent ($files=null)
 
 isReceived ($files=null)
 
 isFiltered ($files=null)
 
 isUploaded ($files=null)
 
- Public Member Functions inherited from Zend_File_Transfer_Adapter_Abstract
 send ($options=null)
 
 receive ($options=null)
 
 isSent ($files=null)
 
 isReceived ($files=null)
 
 isUploaded ($files=null)
 
 isFiltered ($files=null)
 
 setPluginLoader (Zend_Loader_PluginLoader_Interface $loader, $type)
 
 getPluginLoader ($type)
 
 addPrefixPath ($prefix, $path, $type=null)
 
 addPrefixPaths (array $spec)
 
 addValidator ($validator, $breakChainOnFailure=false, $options=null, $files=null)
 
 addValidators (array $validators, $files=null)
 
 setValidators (array $validators, $files=null)
 
 hasValidator ($name)
 
 getValidator ($name)
 
 getValidators ($files=null)
 
 removeValidator ($name)
 
 clearValidators ()
 
 setOptions ($options=array(), $files=null)
 
 getOptions ($files=null)
 
 isValid ($files=null)
 
 getMessages ()
 
 getErrors ()
 
 hasErrors ()
 
 addFilter ($filter, $options=null, $files=null)
 
 addFilters (array $filters, $files=null)
 
 setFilters (array $filters, $files=null)
 
 hasFilter ($name)
 
 getFilter ($name)
 
 getFilters ($files=null)
 
 removeFilter ($name)
 
 clearFilters ()
 
 getFile ()
 
 getFileName ($file=null, $path=true)
 
 getFileInfo ($file=null)
 
 addFile ($file, $validator=null, $filter=null)
 
 getType ()
 
 addType ($type, $validator=null, $filter=null)
 
 setDestination ($destination, $files=null)
 
 getDestination ($files=null)
 
 setTranslator ($translator=null)
 
 getTranslator ()
 
 setDisableTranslator ($flag)
 
 translatorIsDisabled ()
 
 getHash ($hash='crc32', $files=null)
 
 getFileSize ($files=null)
 
 getMimeType ($files=null)
 

Static Public Member Functions

static getProgress ($id=null)
 
static isApcAvailable ()
 
static isUploadProgressAvailable ()
 
- Static Public Member Functions inherited from Zend_File_Transfer_Adapter_Abstract
static getProgress ()
 

Protected Member Functions

 _prepareFiles ()
 
- Protected Member Functions inherited from Zend_File_Transfer_Adapter_Abstract
 _detectFileSize ($value)
 
 _detectMimeType ($value)
 
 _filter ($files=null)
 
 _getTmpDir ()
 
 _isPathWriteable ($path)
 
 _getFiles ($files, $names=false, $noexception=false)
 
 _getValidatorIdentifier ($name)
 
 _getFilterIdentifier ($name)
 

Static Protected Attributes

static $_callbackApc = 'apc_fetch'
 
static $_callbackUploadProgress = 'uploadprogress_get_info'
 

Additional Inherited Members

- Data Fields inherited from Zend_File_Transfer_Adapter_Abstract
const FILTER = 'FILTER'
 
const VALIDATE = 'VALIDATE'
 
- Static Protected Member Functions inherited from Zend_File_Transfer_Adapter_Abstract
static _toByteString ($size)
 
- Protected Attributes inherited from Zend_File_Transfer_Adapter_Abstract
 $_break = array()
 
 $_filters = array()
 
 $_loaders = array()
 
 $_messages = array()
 
 $_translator
 
 $_translatorDisabled = false
 
 $_validators = array()
 
 $_files = array()
 
 $_tmpDir
 
 $_options
 

Detailed Description

Definition at line 35 of file Http.php.

Constructor & Destructor Documentation

◆ __construct()

__construct (   $options = array())

Constructor for Http File Transfers

Parameters
array$optionsOPTIONAL Options to set

Definition at line 45 of file Http.php.

46  {
47  if (ini_get('file_uploads') == false) {
48  #require_once 'Zend/File/Transfer/Exception.php';
49  throw new Zend_File_Transfer_Exception('File uploads are not allowed in your php config!');
50  }
51 
52  $this->setOptions($options);
53  $this->_prepareFiles();
54  $this->addValidator('Upload', false, $this->_files);
55  }
addValidator($validator, $breakChainOnFailure=false, $options=null, $files=null)
Definition: Abstract.php:333
setOptions($options=array(), $files=null)
Definition: Abstract.php:560

Member Function Documentation

◆ _prepareFiles()

_prepareFiles ( )
protected

Prepare the $_FILES array to match the internal syntax of one file per entry

Parameters
array$files
Returns
array

Definition at line 435 of file Http.php.

436  {
437  $this->_files = array();
438  foreach ($_FILES as $form => $content) {
439  if (is_array($content['name'])) {
440  foreach ($content as $param => $file) {
441  foreach ($file as $number => $target) {
442  $this->_files[$form . '_' . $number . '_'][$param] = $target;
443  $this->_files[$form]['multifiles'][$number] = $form . '_' . $number . '_';
444  }
445  }
446 
447  $this->_files[$form]['name'] = $form;
448  foreach($this->_files[$form]['multifiles'] as $key => $value) {
449  $this->_files[$value]['options'] = $this->_options;
450  $this->_files[$value]['validated'] = false;
451  $this->_files[$value]['received'] = false;
452  $this->_files[$value]['filtered'] = false;
453 
454  $mimetype = $this->_detectMimeType($this->_files[$value]);
455  $this->_files[$value]['type'] = $mimetype;
456 
457  $filesize = $this->_detectFileSize($this->_files[$value]);
458  $this->_files[$value]['size'] = $filesize;
459 
460  if ($this->_options['detectInfos']) {
461  $_FILES[$form]['type'][$key] = $mimetype;
462  $_FILES[$form]['size'][$key] = $filesize;
463  }
464  }
465  } else {
466  $this->_files[$form] = $content;
467  $this->_files[$form]['options'] = $this->_options;
468  $this->_files[$form]['validated'] = false;
469  $this->_files[$form]['received'] = false;
470  $this->_files[$form]['filtered'] = false;
471 
472  $mimetype = $this->_detectMimeType($this->_files[$form]);
473  $this->_files[$form]['type'] = $mimetype;
474 
475  $filesize = $this->_detectFileSize($this->_files[$form]);
476  $this->_files[$form]['size'] = $filesize;
477 
478  if ($this->_options['detectInfos']) {
479  $_FILES[$form]['type'] = $mimetype;
480  $_FILES[$form]['size'] = $filesize;
481  }
482  }
483  }
484 
485  return $this;
486  }
$number
Definition: details.phtml:22
$target
Definition: skip.phtml:8
$value
Definition: gender.phtml:16

◆ clearValidators()

clearValidators ( )

Remove an individual validator

Parameters
string$name
Returns
Zend_File_Transfer_Adapter_Abstract

Definition at line 91 of file Http.php.

92  {
93  parent::clearValidators();
94  $this->addValidator('Upload', false, $this->_files);
95 
96  return $this;
97  }
addValidator($validator, $breakChainOnFailure=false, $options=null, $files=null)
Definition: Abstract.php:333

◆ getProgress()

static getProgress (   $id = null)
static

Returns the actual progress of file up-/downloads

Parameters
string$idThe upload to get the progress for
Returns
array|null

Definition at line 307 of file Http.php.

308  {
309  if (!function_exists('apc_fetch') and !function_exists('uploadprogress_get_info')) {
310  #require_once 'Zend/File/Transfer/Exception.php';
311  throw new Zend_File_Transfer_Exception('Neither APC nor uploadprogress extension installed');
312  }
313 
314  $session = 'Zend_File_Transfer_Adapter_Http_ProgressBar';
315  $status = array(
316  'total' => 0,
317  'current' => 0,
318  'rate' => 0,
319  'message' => '',
320  'done' => false
321  );
322 
323  if (is_array($id)) {
324  if (isset($id['progress'])) {
325  $adapter = $id['progress'];
326  }
327 
328  if (isset($id['session'])) {
329  $session = $id['session'];
330  }
331 
332  if (isset($id['id'])) {
333  $id = $id['id'];
334  } else {
335  unset($id);
336  }
337  }
338 
339  if (!empty($id) && (($id instanceof Zend_ProgressBar_Adapter) || ($id instanceof Zend_ProgressBar))) {
340  $adapter = $id;
341  unset($id);
342  }
343 
344  if (empty($id)) {
345  if (!isset($_GET['progress_key'])) {
346  $status['message'] = 'No upload in progress';
347  $status['done'] = true;
348  } else {
349  $id = $_GET['progress_key'];
350  }
351  }
352 
353  if (!empty($id)) {
354  if (self::isApcAvailable()) {
355 
356  $call = call_user_func(self::$_callbackApc, ini_get('apc.rfc1867_prefix') . $id);
357  if (is_array($call)) {
358  $status = $call + $status;
359  }
360  } else if (self::isUploadProgressAvailable()) {
361  $call = call_user_func(self::$_callbackUploadProgress, $id);
362  if (is_array($call)) {
363  $status = $call + $status;
364  $status['total'] = $status['bytes_total'];
365  $status['current'] = $status['bytes_uploaded'];
366  $status['rate'] = $status['speed_average'];
367  if ($status['total'] == $status['current']) {
368  $status['done'] = true;
369  }
370  }
371  }
372 
373  if (!is_array($call)) {
374  $status['done'] = true;
375  $status['message'] = 'Failure while retrieving the upload progress';
376  } else if (!empty($status['cancel_upload'])) {
377  $status['done'] = true;
378  $status['message'] = 'The upload has been canceled';
379  } else {
380  $status['message'] = self::_toByteString($status['current']) . " - " . self::_toByteString($status['total']);
381  }
382 
383  $status['id'] = $id;
384  }
385 
386  if (isset($adapter) && isset($status['id'])) {
387  if ($adapter instanceof Zend_ProgressBar_Adapter) {
388  #require_once 'Zend/ProgressBar.php';
389  $adapter = new Zend_ProgressBar($adapter, 0, $status['total'], $session);
390  }
391 
392  if (!($adapter instanceof Zend_ProgressBar)) {
393  #require_once 'Zend/File/Transfer/Exception.php';
394  throw new Zend_File_Transfer_Exception('Unknown Adapter given');
395  }
396 
397  if ($status['done']) {
398  $adapter->finish();
399  } else {
400  $adapter->update($status['current'], $status['message']);
401  }
402 
403  $status['progress'] = $adapter;
404  }
405 
406  return $status;
407  }
$id
Definition: fieldset.phtml:14
$adapter
Definition: webapi_user.php:16
$status
Definition: order_status.php:8

◆ isApcAvailable()

static isApcAvailable ( )
static

Checks the APC extension for progress information

Returns
boolean

Definition at line 414 of file Http.php.

415  {
416  return (bool) ini_get('apc.enabled') && (bool) ini_get('apc.rfc1867') && is_callable(self::$_callbackApc);
417  }

◆ isFiltered()

isFiltered (   $files = null)

Checks if the file was already filtered

Parameters
string | array$files(Optional) Files to check
Returns
bool

Definition at line 263 of file Http.php.

264  {
265  $files = $this->_getFiles($files, false, true);
266  if (empty($files)) {
267  return false;
268  }
269 
270  foreach ($files as $content) {
271  if ($content['filtered'] !== true) {
272  return false;
273  }
274  }
275 
276  return true;
277  }
_getFiles($files, $names=false, $noexception=false)
Definition: Abstract.php:1464
foreach($appDirs as $dir) $files

◆ isReceived()

isReceived (   $files = null)

Checks if the file was already received

Parameters
string | array$files(Optional) Files to check
Returns
bool

Definition at line 241 of file Http.php.

242  {
243  $files = $this->_getFiles($files, false, true);
244  if (empty($files)) {
245  return false;
246  }
247 
248  foreach ($files as $content) {
249  if ($content['received'] !== true) {
250  return false;
251  }
252  }
253 
254  return true;
255  }
_getFiles($files, $names=false, $noexception=false)
Definition: Abstract.php:1464
foreach($appDirs as $dir) $files

◆ isSent()

isSent (   $files = null)

Checks if the file was already sent

Parameters
string | array$fileFiles to check
Returns
bool
Exceptions
Zend_File_Transfer_ExceptionNot implemented

Definition at line 229 of file Http.php.

230  {
231  #require_once 'Zend/File/Transfer/Exception.php';
232  throw new Zend_File_Transfer_Exception('Method not implemented');
233  }

◆ isUploaded()

isUploaded (   $files = null)

Has a file been uploaded ?

Parameters
array | string | null$file
Returns
bool

Definition at line 285 of file Http.php.

286  {
287  $files = $this->_getFiles($files, false, true);
288  if (empty($files)) {
289  return false;
290  }
291 
292  foreach ($files as $file) {
293  if (empty($file['name'])) {
294  return false;
295  }
296  }
297 
298  return true;
299  }
_getFiles($files, $names=false, $noexception=false)
Definition: Abstract.php:1464
foreach($appDirs as $dir) $files

◆ isUploadProgressAvailable()

static isUploadProgressAvailable ( )
static

Checks the UploadProgress extension for progress information

Returns
boolean

Definition at line 424 of file Http.php.

425  {
426  return is_callable(self::$_callbackUploadProgress);
427  }

◆ isValid()

isValid (   $files = null)

Checks if the files are valid

Parameters
string | array$files(Optional) Files to check
Returns
boolean True if all checks are valid

Definition at line 118 of file Http.php.

119  {
120  // Workaround for WebServer not conforming HTTP and omitting CONTENT_LENGTH
121  $content = 0;
122  if (isset($_SERVER['CONTENT_LENGTH'])) {
123  $content = $_SERVER['CONTENT_LENGTH'];
124  } else if (!empty($_POST)) {
125  $content = serialize($_POST);
126  }
127 
128  // Workaround for a PHP error returning empty $_FILES when form data exceeds php settings
129  if (empty($this->_files) && ($content > 0)) {
130  if (is_array($files)) {
131  if (0 === count($files)) {
132  return false;
133  }
134 
135  $files = current($files);
136  }
137 
138  $temp = array($files => array(
139  'name' => $files,
140  'error' => 1));
141  $validator = $this->_validators['Zend_Validate_File_Upload'];
142  $validator->setFiles($temp)
143  ->isValid($files, null);
144  $this->_messages += $validator->getMessages();
145  return false;
146  }
147 
148  return parent::isValid($files);
149  }
foreach($appDirs as $dir) $files

◆ receive()

receive (   $files = null)

Receive the file from the client (Upload)

Parameters
string | array$files(Optional) Files to receive
Returns
bool

Definition at line 157 of file Http.php.

158  {
159  if (!$this->isValid($files)) {
160  return false;
161  }
162 
163  $check = $this->_getFiles($files);
164  foreach ($check as $file => $content) {
165  if (!$content['received']) {
166  $directory = '';
167  $destination = $this->getDestination($file);
168  if ($destination !== null) {
169  $directory = $destination . DIRECTORY_SEPARATOR;
170  }
171 
172  $filename = $directory . $content['name'];
173  $rename = $this->getFilter('Rename');
174  if ($rename !== null) {
175  $tmp = $rename->getNewName($content['tmp_name']);
176  if ($tmp != $content['tmp_name']) {
177  $filename = $tmp;
178  }
179 
180  if (dirname($filename) == '.') {
181  $filename = $directory . $filename;
182  }
183 
184  $key = array_search(get_class($rename), $this->_files[$file]['filters']);
185  unset($this->_files[$file]['filters'][$key]);
186  }
187 
188  // Should never return false when it's tested by the upload validator
189  if (!move_uploaded_file($content['tmp_name'], $filename)) {
190  if ($content['options']['ignoreNoFile']) {
191  $this->_files[$file]['received'] = true;
192  $this->_files[$file]['filtered'] = true;
193  continue;
194  }
195 
196  $this->_files[$file]['received'] = false;
197  return false;
198  }
199 
200  if ($rename !== null) {
201  $this->_files[$file]['destination'] = dirname($filename);
202  $this->_files[$file]['name'] = basename($filename);
203  }
204 
205  $this->_files[$file]['tmp_name'] = $filename;
206  $this->_files[$file]['received'] = true;
207  }
208 
209  if (!$content['filtered']) {
210  if (!$this->_filter($file)) {
211  $this->_files[$file]['filtered'] = false;
212  return false;
213  }
214 
215  $this->_files[$file]['filtered'] = true;
216  }
217  }
218 
219  return true;
220  }
_getFiles($files, $names=false, $noexception=false)
Definition: Abstract.php:1464
foreach($appDirs as $dir) $files

◆ removeValidator()

removeValidator (   $name)

Remove an individual validator

Parameters
string$name
Returns
Zend_File_Transfer_Adapter_Abstract

Definition at line 76 of file Http.php.

77  {
78  if ($name == 'Upload') {
79  return $this;
80  }
81 
82  return parent::removeValidator($name);
83  }
if(!isset($_GET['name'])) $name
Definition: log.php:14

◆ send()

send (   $options = null)

Send the file to the client (Download)

Parameters
string | array$optionsOptions for the file(s) to send
Returns
void
Exceptions
Zend_File_Transfer_ExceptionNot implemented

Definition at line 106 of file Http.php.

107  {
108  #require_once 'Zend/File/Transfer/Exception.php';
109  throw new Zend_File_Transfer_Exception('Method not implemented');
110  }

◆ setValidators()

setValidators ( array  $validators,
  $files = null 
)

Sets a validator for the class, erasing all previous set

Parameters
string | array$validatorValidator to set
string | array$filesFiles to limit this validator to
Returns
Zend_File_Transfer_Adapter

Definition at line 64 of file Http.php.

65  {
66  $this->clearValidators();
67  return $this->addValidators($validators, $files);
68  }
addValidators(array $validators, $files=null)
Definition: Abstract.php:379
foreach($appDirs as $dir) $files

Field Documentation

◆ $_callbackApc

$_callbackApc = 'apc_fetch'
staticprotected

Definition at line 37 of file Http.php.

◆ $_callbackUploadProgress

$_callbackUploadProgress = 'uploadprogress_get_info'
staticprotected

Definition at line 38 of file Http.php.


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