PHP: Get the mime type for a file
If you need to get the mime type for a file in PHP you can use this function which wrappers the finfo_open() function.
function mime_from_filename($filename) {
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $filename);
finfo_close($finfo);
return $mine;
}
Note: This function requires the file to exist on the disk.



