Verzeichnisstruktur phpBB-3.2.0


Veröffentlicht
06.01.2017

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

      (Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

FileBag.php

Zuletzt modifiziert: 09.10.2024, 12:54 - Dateigröße: 3.82 KiB


 001  <?php
 002   
 003  /*
 004   * This file is part of the Symfony package.
 005   *
 006   * (c) Fabien Potencier <fabien@symfony.com>
 007   *
 008   * For the full copyright and license information, please view the LICENSE
 009   * file that was distributed with this source code.
 010   */
 011   
 012  namespace Symfony\Component\HttpFoundation;
 013   
 014  use Symfony\Component\HttpFoundation\File\UploadedFile;
 015   
 016  /**
 017   * FileBag is a container for uploaded files.
 018   *
 019   * @author Fabien Potencier <fabien@symfony.com>
 020   * @author Bulat Shakirzyanov <mallluhuct@gmail.com>
 021   */
 022  class FileBag extends ParameterBag
 023  {
 024      private static $fileKeys = array('error', 'name', 'size', 'tmp_name', 'type');
 025   
 026      /**
 027       * Constructor.
 028       *
 029       * @param array $parameters An array of HTTP files
 030       */
 031      public function __construct(array $parameters = array())
 032      {
 033          $this->replace($parameters);
 034      }
 035   
 036      /**
 037       * {@inheritdoc}
 038       */
 039      public function replace(array $files = array())
 040      {
 041          $this->parameters = array();
 042          $this->add($files);
 043      }
 044   
 045      /**
 046       * {@inheritdoc}
 047       */
 048      public function set($key, $value)
 049      {
 050          if (!is_array($value) && !$value instanceof UploadedFile) {
 051              throw new \InvalidArgumentException('An uploaded file must be an array or an instance of UploadedFile.');
 052          }
 053   
 054          parent::set($key, $this->convertFileInformation($value));
 055      }
 056   
 057      /**
 058       * {@inheritdoc}
 059       */
 060      public function add(array $files = array())
 061      {
 062          foreach ($files as $key => $file) {
 063              $this->set($key, $file);
 064          }
 065      }
 066   
 067      /**
 068       * Converts uploaded files to UploadedFile instances.
 069       *
 070       * @param array|UploadedFile $file A (multi-dimensional) array of uploaded file information
 071       *
 072       * @return array A (multi-dimensional) array of UploadedFile instances
 073       */
 074      protected function convertFileInformation($file)
 075      {
 076          if ($file instanceof UploadedFile) {
 077              return $file;
 078          }
 079   
 080          $file = $this->fixPhpFilesArray($file);
 081          if (is_array($file)) {
 082              $keys = array_keys($file);
 083              sort($keys);
 084   
 085              if ($keys == self::$fileKeys) {
 086                  if (UPLOAD_ERR_NO_FILE == $file['error']) {
 087                      $file = null;
 088                  } else {
 089                      $file = new UploadedFile($file['tmp_name'], $file['name'], $file['type'], $file['size'], $file['error']);
 090                  }
 091              } else {
 092                  $file = array_map(array($this, 'convertFileInformation'), $file);
 093              }
 094          }
 095   
 096          return $file;
 097      }
 098   
 099      /**
 100       * Fixes a malformed PHP $_FILES array.
 101       *
 102       * PHP has a bug that the format of the $_FILES array differs, depending on
 103       * whether the uploaded file fields had normal field names or array-like
 104       * field names ("normal" vs. "parent[child]").
 105       *
 106       * This method fixes the array to look like the "normal" $_FILES array.
 107       *
 108       * It's safe to pass an already converted array, in which case this method
 109       * just returns the original array unmodified.
 110       *
 111       * @param array $data
 112       *
 113       * @return array
 114       */
 115      protected function fixPhpFilesArray($data)
 116      {
 117          if (!is_array($data)) {
 118              return $data;
 119          }
 120   
 121          $keys = array_keys($data);
 122          sort($keys);
 123   
 124          if (self::$fileKeys != $keys || !isset($data['name']) || !is_array($data['name'])) {
 125              return $data;
 126          }
 127   
 128          $files = $data;
 129          foreach (self::$fileKeys as $k) {
 130              unset($files[$k]);
 131          }
 132   
 133          foreach ($data['name'] as $key => $name) {
 134              $files[$key] = $this->fixPhpFilesArray(array(
 135                  'error' => $data['error'][$key],
 136                  'name' => $name,
 137                  'type' => $data['type'][$key],
 138                  'tmp_name' => $data['tmp_name'][$key],
 139                  'size' => $data['size'][$key],
 140              ));
 141          }
 142   
 143          return $files;
 144      }
 145  }
 146