"Fossies" - the Fresh Open Source Software Archive

Member "phpMyAdmin-5.1.0-english/libraries/classes/Mime.php" (24 Feb 2021, 916 Bytes) of package /linux/www/phpMyAdmin-5.1.0-english.zip:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PHP source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "Mime.php" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 5.0.4-english_vs_5.1.0-english.

    1 <?php
    2 /**
    3  * MIME detection code.
    4  *
    5  * @todo Maybe we could try to use fileinfo module if loaded
    6  */
    7 
    8 declare(strict_types=1);
    9 
   10 namespace PhpMyAdmin;
   11 
   12 use function chr;
   13 use function mb_strlen;
   14 use function mb_substr;
   15 use function substr;
   16 
   17 /**
   18  * PhpMyAdmin\Mime class;
   19  */
   20 class Mime
   21 {
   22     /**
   23      * Tries to detect MIME type of content.
   24      *
   25      * @param string $test First few bytes of content to use for detection
   26      *
   27      * @return string
   28      */
   29     public static function detect(&$test)
   30     {
   31         $len = mb_strlen($test);
   32         if ($len >= 2 && $test[0] == chr(0xff) && $test[1] == chr(0xd8)) {
   33             return 'image/jpeg';
   34         }
   35         if ($len >= 3 && substr($test, 0, 3) === 'GIF') {
   36             return 'image/gif';
   37         }
   38         if ($len >= 4 && mb_substr($test, 0, 4) == "\x89PNG") {
   39             return 'image/png';
   40         }
   41 
   42         return 'application/octet-stream';
   43     }
   44 }