$mtype = '';
// magic_mime module installed?
if (function_exists('mime_content_type')) {
$mtype = mime_content_type($file_path);
}
// fileinfo module installed?
else if (function_exists('finfo_file')) {
$finfo = finfo_open(FILEINFO_MIME); // return mime type
$mtype = finfo_file($finfo, $file_path);
finfo_close($finfo);
}
Note: this code tries to use
magic_mime or
fileinfo module for mime type detection. Some hosters does not have these modules installed.