If you start Linux and you have an extension, you can simply read the MIME type from /etc/mime.types, creating a hash array. Then you can store this in memory and just call MIME using the array key :)
function get_mime_types() { $mime_types = array(); if ( file_exists('/etc/mime.types') && ($fh = fopen('/etc/mime.types', 'r')) !== false ) { while (($line = fgets($fh)) !== false) { if (!trim($line) || substr($line, 0, 1) === '#') continue; $mime_type = preg_split('/\t+/', rtrim($line)); if ( is_array($mime_type) && isset($mime_type[0]) && $mime_type[0] && isset($mime_type[1]) && $mime_type[1] ) { foreach (explode(' ', $mime_type[1]) as $ext) { $mime_types[$ext] = $mime_type[0]; } } } fclose($fh); } return $mime_types; }
techouse Aug 24 '16 at 18:58 2016-08-24 18:58
source share