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

FileBinaryMimeTypeGuesser.php

Zuletzt modifiziert: 01.05.2026, 11:28 - Dateigröße: 2.49 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\MimeType;
 013   
 014  use Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException;
 015  use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
 016   
 017  /**
 018   * Guesses the mime type with the binary "file" (only available on *nix).
 019   *
 020   * @author Bernhard Schussek <bschussek@gmail.com>
 021   */
 022  class FileBinaryMimeTypeGuesser implements MimeTypeGuesserInterface
 023  {
 024      private $cmd;
 025   
 026      /**
 027       * The $cmd pattern must contain a "%s" string that will be replaced
 028       * with the file name to guess.
 029       *
 030       * The command output must start with the mime type of the file.
 031       *
 032       * @param string $cmd The command to run to get the mime type of a file
 033       */
 034      public function __construct($cmd = 'file -b --mime -- %s 2>/dev/null')
 035      {
 036          $this->cmd = $cmd;
 037      }
 038   
 039      /**
 040       * Returns whether this guesser is supported on the current OS.
 041       *
 042       * @return bool
 043       */
 044      public static function isSupported()
 045      {
 046          static $supported = null;
 047   
 048          if (null !== $supported) {
 049              return $supported;
 050          }
 051   
 052          if ('\\' === \DIRECTORY_SEPARATOR || !\function_exists('passthru') || !\function_exists('escapeshellarg')) {
 053              return $supported = false;
 054          }
 055   
 056          ob_start();
 057          passthru('command -v file', $exitStatus);
 058          $binPath = trim(ob_get_clean());
 059   
 060          return $supported = 0 === $exitStatus && '' !== $binPath;
 061      }
 062   
 063      /**
 064       * {@inheritdoc}
 065       */
 066      public function guess($path)
 067      {
 068          if (!is_file($path)) {
 069              throw new FileNotFoundException($path);
 070          }
 071   
 072          if (!is_readable($path)) {
 073              throw new AccessDeniedException($path);
 074          }
 075   
 076          if (!self::isSupported()) {
 077              return null;
 078          }
 079   
 080          ob_start();
 081   
 082          // need to use --mime instead of -i. see #6641
 083          passthru(sprintf($this->cmd, escapeshellarg((0 === strpos($path, '-') ? './' : '').$path)), $return);
 084          if ($return > 0) {
 085              ob_end_clean();
 086   
 087              return null;
 088          }
 089   
 090          $type = trim(ob_get_clean());
 091   
 092          if (!preg_match('#^([a-z0-9\-]+/[a-z0-9\-\+\.]+)#i', $type, $match)) {
 093              // it's not a type, but an error message
 094              return null;
 095          }
 096   
 097          return $match[1];
 098      }
 099  }
 100