PHP check remote image valid using curl without download content

Using curl, without download content, remote image valid can be known.
Example:

$url = "http://www.example.com/image.jpg";
echo check_remote_image($url);

function check_remote_image($url)
    {
    	$ch = curl_init();
    	curl_setopt($ch, CURLOPT_URL,$url);
    	// don't download content
    	curl_setopt($ch, CURLOPT_NOBODY, 1);
	curl_setopt($ch, CURLOPT_HEADER, 0);
	curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD');
    	curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
    	curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
    	if(curl_exec($ch)!==FALSE)
    	{
    		return true;
    	}
    	else
    	{
    		return false;
    	}

    	curl_close($ch);
    }

Output: false

By Keenlio, May 20, 2014

What do you think?

Leave a Reply

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


− four = 5

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>