Translated using Weblate (Romanian)
[phpmyadmin.git] / libraries / classes / Mime.php
blob75b9eac7e678e59e9a7ac6d5b569db390ecfcfe6
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * MIME detection code.
6 * @package PhpMyAdmin
7 * @todo Maybe we could try to use fileinfo module if loaded
8 */
9 declare(strict_types=1);
11 namespace PhpMyAdmin;
13 /**
14 * PhpMyAdmin\Mime class;
16 * @package PhpMyAdmin
18 class Mime
20 /**
21 * Tries to detect MIME type of content.
23 * @param string $test First few bytes of content to use for detection
25 * @return string
27 public static function detect(&$test)
29 $len = mb_strlen($test);
30 if ($len >= 2 && $test[0] == chr(0xff) && $test[1] == chr(0xd8)) {
31 return 'image/jpeg';
33 if ($len >= 3 && substr($test, 0, 3) == 'GIF') {
34 return 'image/gif';
36 if ($len >= 4 && mb_substr($test, 0, 4) == "\x89PNG") {
37 return 'image/png';
39 return 'application/octet-stream';