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

File.php

Zuletzt modifiziert: 01.05.2026, 11:27 - Dateigröße: 4.12 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\File;
 013   
 014  use Symfony\Component\HttpFoundation\File\Exception\FileException;
 015  use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
 016  use Symfony\Component\HttpFoundation\File\MimeType\ExtensionGuesser;
 017  use Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser;
 018   
 019  /**
 020   * A file in the file system.
 021   *
 022   * @author Bernhard Schussek <bschussek@gmail.com>
 023   */
 024  class File extends \SplFileInfo
 025  {
 026      /**
 027       * Constructs a new file from the given path.
 028       *
 029       * @param string $path      The path to the file
 030       * @param bool   $checkPath Whether to check the path or not
 031       *
 032       * @throws FileNotFoundException If the given path is not a file
 033       */
 034      public function __construct($path, $checkPath = true)
 035      {
 036          if ($checkPath && !is_file($path)) {
 037              throw new FileNotFoundException($path);
 038          }
 039   
 040          parent::__construct($path);
 041      }
 042   
 043      /**
 044       * Returns the extension based on the mime type.
 045       *
 046       * If the mime type is unknown, returns null.
 047       *
 048       * This method uses the mime type as guessed by getMimeType()
 049       * to guess the file extension.
 050       *
 051       * @return string|null The guessed extension or null if it cannot be guessed
 052       *
 053       * @see ExtensionGuesser
 054       * @see getMimeType()
 055       */
 056      public function guessExtension()
 057      {
 058          $type = $this->getMimeType();
 059          $guesser = ExtensionGuesser::getInstance();
 060   
 061          return $guesser->guess($type);
 062      }
 063   
 064      /**
 065       * Returns the mime type of the file.
 066       *
 067       * The mime type is guessed using a MimeTypeGuesser instance, which uses finfo(),
 068       * mime_content_type() and the system binary "file" (in this order), depending on
 069       * which of those are available.
 070       *
 071       * @return string|null The guessed mime type (e.g. "application/pdf")
 072       *
 073       * @see MimeTypeGuesser
 074       */
 075      public function getMimeType()
 076      {
 077          $guesser = MimeTypeGuesser::getInstance();
 078   
 079          return $guesser->guess($this->getPathname());
 080      }
 081   
 082      /**
 083       * Moves the file to a new location.
 084       *
 085       * @param string $directory The destination folder
 086       * @param string $name      The new file name
 087       *
 088       * @return self A File object representing the new file
 089       *
 090       * @throws FileException if the target file could not be created
 091       */
 092      public function move($directory, $name = null)
 093      {
 094          $target = $this->getTargetFile($directory, $name);
 095   
 096          set_error_handler(function ($type, $msg) use (&$error) { $error = $msg; });
 097          $renamed = rename($this->getPathname(), $target);
 098          restore_error_handler();
 099          if (!$renamed) {
 100              throw new FileException(sprintf('Could not move the file "%s" to "%s" (%s).', $this->getPathname(), $target, strip_tags($error)));
 101          }
 102   
 103          @chmod($target, 0666 & ~umask());
 104   
 105          return $target;
 106      }
 107   
 108      protected function getTargetFile($directory, $name = null)
 109      {
 110          if (!is_dir($directory)) {
 111              if (false === @mkdir($directory, 0777, true) && !is_dir($directory)) {
 112                  throw new FileException(sprintf('Unable to create the "%s" directory.', $directory));
 113              }
 114          } elseif (!is_writable($directory)) {
 115              throw new FileException(sprintf('Unable to write in the "%s" directory.', $directory));
 116          }
 117   
 118          $target = rtrim($directory, '/\\').\DIRECTORY_SEPARATOR.(null === $name ? $this->getBasename() : $this->getName($name));
 119   
 120          return new self($target, false);
 121      }
 122   
 123      /**
 124       * Returns locale independent base name of the given path.
 125       *
 126       * @param string $name The new file name
 127       *
 128       * @return string containing
 129       */
 130      protected function getName($name)
 131      {
 132          $originalName = str_replace('\\', '/', $name);
 133          $pos = strrpos($originalName, '/');
 134          $originalName = false === $pos ? $originalName : substr($originalName, $pos + 1);
 135   
 136          return $originalName;
 137      }
 138  }
 139