Verzeichnisstruktur phpBB-3.3.15


Veröffentlicht
28.08.2024

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

FileinfoMimeTypeGuesser.php

Zuletzt modifiziert: 02.04.2025, 15:03 - Dateigröße: 1.84 KiB


01  <?php
02   
03  /*
04   * This file is part of the Symfony package.
05   *
06   * (c) Fabien Potencier <fabien@symfony.com>
07   *
08   * For the full copyright and license information, please view the LICENSE
09   * file that was distributed with this source code.
10   */
11   
12  namespace Symfony\Component\HttpFoundation\File\MimeType;
13   
14  use Symfony\Component\HttpFoundation\File\Exception\AccessDeniedException;
15  use Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException;
16   
17  /**
18   * Guesses the mime type using the PECL extension FileInfo.
19   *
20   * @author Bernhard Schussek <bschussek@gmail.com>
21   */
22  class FileinfoMimeTypeGuesser implements MimeTypeGuesserInterface
23  {
24      private $magicFile;
25   
26      /**
27       * @param string $magicFile A magic file to use with the finfo instance
28       *
29       * @see https://php.net/finfo-open
30       */
31      public function __construct($magicFile = null)
32      {
33          $this->magicFile = $magicFile;
34      }
35   
36      /**
37       * Returns whether this guesser is supported on the current OS/PHP setup.
38       *
39       * @return bool
40       */
41      public static function isSupported()
42      {
43          return \function_exists('finfo_open');
44      }
45   
46      /**
47       * {@inheritdoc}
48       */
49      public function guess($path)
50      {
51          if (!is_file($path)) {
52              throw new FileNotFoundException($path);
53          }
54   
55          if (!is_readable($path)) {
56              throw new AccessDeniedException($path);
57          }
58   
59          if (!self::isSupported()) {
60              return null;
61          }
62   
63          if (!$finfo = new \finfo(\FILEINFO_MIME_TYPE, $this->magicFile)) {
64              return null;
65          }
66          $mimeType = $finfo->file($path);
67   
68          if ($mimeType && 0 === (\strlen($mimeType) % 2)) {
69              $mimeStart = substr($mimeType, 0, \strlen($mimeType) >> 1);
70              $mimeType = $mimeStart.$mimeStart === $mimeType ? $mimeStart : $mimeType;
71          }
72   
73          return $mimeType;
74      }
75  }
76