Skip to content

Instantly share code, notes, and snippets.

@abbotto
Created August 16, 2013 12:55
Show Gist options
  • Save abbotto/6249644 to your computer and use it in GitHub Desktop.
Save abbotto/6249644 to your computer and use it in GitHub Desktop.
A function to get file mime-types with curl.
function file_mime($_path) {
$ch = curl_init($_path);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
$content_info = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
curl_close($ch);
$content_parts = explode(";", $content_info);
$mime = $content_parts[0];
if(isset($mime) && !empty($mime)){return $mime;}
else if (function_exists('finfo_open')) {
$get_info = new finfo;
$mime = $finfo->file($_path, FILEINFO_MIME);
return $mime;
}
else { $mime = 'application/octet-stream'; return $mime;}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment