5 * @todo Maybe we could try to use fileinfo module if loaded
8 declare(strict_types
=1);
13 use function mb_strlen
;
14 use function str_starts_with
;
17 * Handles mime type detection
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)) {
33 if ($len >= 3 && str_starts_with($test, 'GIF')) {
37 if ($len >= 4 && str_starts_with($test, "\x89PNG")) {
41 return 'application/octet-stream';