[ Index ]

PHP Cross Reference of phpBB-3.2.11-deutsch

title

Body

[close]

/phpbb/files/types/ -> local.php (source)

   1  <?php
   2  /**
   3   *
   4   * This file is part of the phpBB Forum Software package.
   5   *
   6   * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7   * @license GNU General Public License, version 2 (GPL-2.0)
   8   *
   9   * For full copyright and license information, please see
  10   * the docs/CREDITS.txt file.
  11   *
  12   */
  13  
  14  namespace phpbb\files\types;
  15  
  16  use bantu\IniGetWrapper\IniGetWrapper;
  17  use phpbb\files\factory;
  18  use phpbb\files\filespec;
  19  use phpbb\language\language;
  20  use phpbb\request\request_interface;
  21  
  22  class local extends base
  23  {
  24      /** @var factory Files factory */
  25      protected $factory;
  26  
  27      /** @var language */
  28      protected $language;
  29  
  30      /** @var IniGetWrapper */
  31      protected $php_ini;
  32  
  33      /** @var request_interface */
  34      protected $request;
  35  
  36      /** @var \phpbb\files\upload */
  37      protected $upload;
  38  
  39      /**
  40       * Construct a form upload type
  41       *
  42       * @param factory $factory Files factory
  43       * @param language $language Language class
  44       * @param IniGetWrapper $php_ini ini_get() wrapper
  45       * @param request_interface $request Request object
  46       */
  47  	public function __construct(factory $factory, language $language, IniGetWrapper $php_ini, request_interface $request)
  48      {
  49          $this->factory = $factory;
  50          $this->language = $language;
  51          $this->php_ini = $php_ini;
  52          $this->request = $request;
  53      }
  54  
  55      /**
  56       * {@inheritdoc}
  57       */
  58  	public function upload()
  59      {
  60          $args = func_get_args();
  61          return $this->local_upload($args[0], isset($args[1]) ? $args[1] : false);
  62      }
  63  
  64      /**
  65       * Move file from another location to phpBB
  66       *
  67       * @param string $source_file Filename of source file
  68       * @param array|bool $filedata Array with filedata or false
  69       *
  70       * @return filespec Object "filespec" is returned, all further operations can be done with this object
  71       */
  72  	protected function local_upload($source_file, $filedata = false)
  73      {
  74          $upload = $this->get_upload_ary($source_file, $filedata);
  75  
  76          /** @var filespec $file */
  77          $file = $this->factory->get('filespec')
  78              ->set_upload_ary($upload)
  79              ->set_upload_namespace($this->upload);
  80  
  81          if ($file->init_error())
  82          {
  83              $file->error[] = '';
  84              return $file;
  85          }
  86  
  87          // PHP Upload file size check
  88          $file = $this->check_upload_size($file);
  89          if (count($file->error))
  90          {
  91              return $file;
  92          }
  93  
  94          // Not correctly uploaded
  95          if (!$file->is_uploaded())
  96          {
  97              $file->error[] = $this->language->lang($this->upload->error_prefix . 'NOT_UPLOADED');
  98              return $file;
  99          }
 100  
 101          $this->upload->common_checks($file);
 102          $this->request->overwrite('local', $upload, request_interface::FILES);
 103  
 104          return $file;
 105      }
 106  
 107      /**
 108       * Retrieve upload array
 109       *
 110       * @param string $source_file Source file name
 111       * @param array $filedata File data array
 112       *
 113       * @return array Upload array
 114       */
 115  	protected function get_upload_ary($source_file, $filedata)
 116      {
 117          $upload = array();
 118  
 119          $upload['local_mode'] = true;
 120          $upload['tmp_name'] = $source_file;
 121  
 122          if ($filedata === false)
 123          {
 124              $upload['name'] = utf8_basename($source_file);
 125              $upload['size'] = 0;
 126          }
 127          else
 128          {
 129              $upload['name'] = $filedata['realname'];
 130              $upload['size'] = $filedata['size'];
 131              $upload['type'] = $filedata['type'];
 132          }
 133  
 134          return $upload;
 135      }
 136  }


Generated: Wed Nov 11 20:33:01 2020 Cross-referenced by PHPXref 0.7.1