Skip to content

Instantly share code, notes, and snippets.

@hasnhasan
Created December 30, 2016 13:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hasnhasan/bb92d3ceaf2f22b5525b9d3e04e50d23 to your computer and use it in GitHub Desktop.
Save hasnhasan/bb92d3ceaf2f22b5525b9d3e04e50d23 to your computer and use it in GitHub Desktop.
function isImage($url = '') {
if (!strstr($url,'http')) return false;
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_MAXREDIRS, 3);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT ,5);
curl_setopt($ch,CURLOPT_TIMEOUT, 15);
curl_exec($ch);
$contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
curl_close($ch);
if (strstr($contentType,'image') || strstr($contentType,'octet-stream')) return true;
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment