Verzeichnisstruktur phpBB-3.1.0


Veröffentlicht
27.10.2014

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