Translated using Weblate (Portuguese)
[phpmyadmin.git] / src / Mime.php
blobbe64cc1a02539b315f6895f56ddcee77c296b143
1 <?php
2 /**
3 * MIME detection code.
5 * @todo Maybe we could try to use fileinfo module if loaded
6 */
8 declare(strict_types=1);
10 namespace PhpMyAdmin;
12 use function chr;
13 use function mb_strlen;
14 use function str_starts_with;
16 /**
17 * Handles mime type detection
19 class Mime
21 /**
22 * Tries to detect MIME type of content.
24 * @param string $test First few bytes of content to use for detection
26 public static function detect(string $test): string
28 $len = mb_strlen($test);
29 if ($len >= 2 && $test[0] === chr(0xff) && $test[1] === chr(0xd8)) {
30 return 'image/jpeg';
33 if ($len >= 3 && str_starts_with($test, 'GIF')) {
34 return 'image/gif';
37 if ($len >= 4 && str_starts_with($test, "\x89PNG")) {
38 return 'image/png';
41 return 'application/octet-stream';