Get remote file mime type

Here’s a function that can get the mime type of a remote file. It will also follow any redirects that are in place.

function get_url_mime_type($url)

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
return curl_getinfo($ch, CURLINFO_CONTENT_TYPE);


Leave a Reply

Your email address will not be published. Required fields are marked *