Skip to content

Instantly share code, notes, and snippets.

@eliza411
Created September 8, 2013 18:42
Show Gist options
  • Save eliza411/6487322 to your computer and use it in GitHub Desktop.
Save eliza411/6487322 to your computer and use it in GitHub Desktop.
Test that a valid image is actually being loaded.
public function checkForImage($url) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
// get the content type
$mime_type = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
if (strpos($mime_type, 'image/') === FALSE) {
throw new Exception (sprintf('%s did not return an image', $url));
}
@svogt0511
Copy link

Thanks. This is exactly what I needed.

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