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.



Note: Replies will be formatted with PHP Markdown Extra syntax.

Name: Email (Not Required):
 
Logged IP: 216.73.216.48
To prevent spam please submit by clicking the kitten: