PHP check whether image exists on remote URL

The simplest and fastest way is to use curl if your host supports curl.

    /**
     * check remote image file url
     */
    static public function check_remote_file($url)
    {
    	$ch = curl_init();
    	curl_setopt($ch, CURLOPT_URL,$url);
    	// don't download content
    	curl_setopt($ch, CURLOPT_NOBODY, 1);
    	curl_setopt($ch, CURLOPT_FAILONERROR, 1);
    	curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    	if(curl_exec($ch)!==FALSE)
    	{
    		return true;
    	}
    	else
    	{
    		return false;
    	}

    }

By Keenlio, February 12, 2014

What do you think?

Leave a Reply

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


× 7 = forty two

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>