Created
September 8, 2013 18:42
-
-
Save eliza411/6487322 to your computer and use it in GitHub Desktop.
Test that a valid image is actually being loaded.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks. This is exactly what I needed.