Verzeichnisstruktur phpBB-3.3.16


Veröffentlicht
27.04.2026

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: 01.05.2026, 11:26 - Dateigröße: 3.84 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 = ['error', 'name', 'size', 'tmp_name', 'type'];
 025   
 026      /**
 027       * @param array $parameters An array of HTTP files
 028       */
 029      public function __construct(array $parameters = [])
 030      {
 031          $this->replace($parameters);
 032      }
 033   
 034      /**
 035       * {@inheritdoc}
 036       */
 037      public function replace(array $files = [])
 038      {
 039          $this->parameters = [];
 040          $this->add($files);
 041      }
 042   
 043      /**
 044       * {@inheritdoc}
 045       */
 046      public function set($key, $value)
 047      {
 048          if (!\is_array($value) && !$value instanceof UploadedFile) {
 049              throw new \InvalidArgumentException('An uploaded file must be an array or an instance of UploadedFile.');
 050          }
 051   
 052          parent::set($key, $this->convertFileInformation($value));
 053      }
 054   
 055      /**
 056       * {@inheritdoc}
 057       */
 058      public function add(array $files = [])
 059      {
 060          foreach ($files as $key => $file) {
 061              $this->set($key, $file);
 062          }
 063      }
 064   
 065      /**
 066       * Converts uploaded files to UploadedFile instances.
 067       *
 068       * @param array|UploadedFile $file A (multi-dimensional) array of uploaded file information
 069       *
 070       * @return UploadedFile[]|UploadedFile|null A (multi-dimensional) array of UploadedFile instances
 071       */
 072      protected function convertFileInformation($file)
 073      {
 074          if ($file instanceof UploadedFile) {
 075              return $file;
 076          }
 077   
 078          if (\is_array($file)) {
 079              $file = $this->fixPhpFilesArray($file);
 080              $keys = array_keys($file);
 081              sort($keys);
 082   
 083              if ($keys == self::$fileKeys) {
 084                  if (\UPLOAD_ERR_NO_FILE == $file['error']) {
 085                      $file = null;
 086                  } else {
 087                      $file = new UploadedFile($file['tmp_name'], $file['name'], $file['type'], $file['size'], $file['error']);
 088                  }
 089              } else {
 090                  $file = array_map([$this, 'convertFileInformation'], $file);
 091                  if (array_keys($keys) === $keys) {
 092                      $file = array_filter($file);
 093                  }
 094              }
 095          }
 096   
 097          return $file;
 098      }
 099   
 100      /**
 101       * Fixes a malformed PHP $_FILES array.
 102       *
 103       * PHP has a bug that the format of the $_FILES array differs, depending on
 104       * whether the uploaded file fields had normal field names or array-like
 105       * field names ("normal" vs. "parent[child]").
 106       *
 107       * This method fixes the array to look like the "normal" $_FILES array.
 108       *
 109       * It's safe to pass an already converted array, in which case this method
 110       * just returns the original array unmodified.
 111       *
 112       * @param array $data
 113       *
 114       * @return array
 115       */
 116      protected function fixPhpFilesArray($data)
 117      {
 118          $keys = array_keys($data);
 119          sort($keys);
 120   
 121          if (self::$fileKeys != $keys || !isset($data['name']) || !\is_array($data['name'])) {
 122              return $data;
 123          }
 124   
 125          $files = $data;
 126          foreach (self::$fileKeys as $k) {
 127              unset($files[$k]);
 128          }
 129   
 130          foreach ($data['name'] as $key => $name) {
 131              $files[$key] = $this->fixPhpFilesArray([
 132                  'error' => $data['error'][$key],
 133                  'name' => $name,
 134                  'type' => $data['type'][$key],
 135                  'tmp_name' => $data['tmp_name'][$key],
 136                  'size' => $data['size'][$key],
 137              ]);
 138          }
 139   
 140          return $files;
 141      }
 142  }
 143