Skip to content

Instantly share code, notes, and snippets.

@karlgroves
Created November 19, 2013 13:49
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karlgroves/7545632 to your computer and use it in GitHub Desktop.
Save karlgroves/7545632 to your computer and use it in GitHub Desktop.
PHP function to get the MIME type of a remote file.
function getRemoteMimeType($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
# get the content type
return curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
}
@karlgroves
Copy link
Author

Note: The downside to this is that curl_exec grabs the entire file first.

PHP's built-in get_headers function should be used if you don't want to grab the whole file.

@bishwajitcadhikary
Copy link

Note: The downside to this is that curl_exec grabs the entire file first.

PHP's built-in get_headers function should be used if you don't want to grab the whole file.

it's always return "Content-Type" => "application/octet-stream"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment