* Add remaining native return type hints to flush out bugs Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * Cast the mixed value to int Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * Fix tests Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * getAutoIncrement() is supposed to return string Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * Cast values to string in DummyResult Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * Make getCollation() return non-nullable string Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * Cast seqInIndex to int Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * Cast $cardinality to int Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * createFile may return false Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * Remove redundant cast Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> * Update baselines Signed-off-by: Kamil Tekiela <tekiela246@gmail.com> --------- Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
45 lines
910 B
PHP
45 lines
910 B
PHP
<?php
|
|
/**
|
|
* MIME detection code.
|
|
*
|
|
* @todo Maybe we could try to use fileinfo module if loaded
|
|
*/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace PhpMyAdmin;
|
|
|
|
use function chr;
|
|
use function mb_strlen;
|
|
use function mb_substr;
|
|
use function substr;
|
|
|
|
/**
|
|
* Handles mime type detection
|
|
*/
|
|
class Mime
|
|
{
|
|
/**
|
|
* Tries to detect MIME type of content.
|
|
*
|
|
* @param string $test First few bytes of content to use for detection
|
|
*/
|
|
public static function detect(string $test): string
|
|
{
|
|
$len = mb_strlen($test);
|
|
if ($len >= 2 && $test[0] === chr(0xff) && $test[1] === chr(0xd8)) {
|
|
return 'image/jpeg';
|
|
}
|
|
|
|
if ($len >= 3 && substr($test, 0, 3) === 'GIF') {
|
|
return 'image/gif';
|
|
}
|
|
|
|
if ($len >= 4 && mb_substr($test, 0, 4) == "\x89PNG") {
|
|
return 'image/png';
|
|
}
|
|
|
|
return 'application/octet-stream';
|
|
}
|
|
}
|