Skip to content

Instantly share code, notes, and snippets.

@gsmcwhirter
Created October 7, 2009 14:27
Show Gist options
  • Save gsmcwhirter/204066 to your computer and use it in GitHub Desktop.
Save gsmcwhirter/204066 to your computer and use it in GitHub Desktop.
<?php
function FileMimeType($file)
{
static $finfo;
if(extension_loaded("fileinfo") || @dl("fileinfo.so"))
{
if(!($finfo instanceOf finfo))
{
$finfo = new finfo(FILEINFO_MIME|FILEINFO_SYMLINK|FILEINFO_PRESERVE_ATIME, SETTINGS::$MimeMagicFile);
}
if($finfo !== false)
{
return $finfo->file(realpath($file));
}
}
if ( function_exists('mime_content_type '))
{
return mime_content_type(realpath($file));
}
else
{
return trim(exec('file -bi '.escapeshellarg( realpath($file) )));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment