How to find if a remote image exists or can be displayed?
I've been using this function to check for broken images and it works for most of them but it says that some don't exist when they do display fine on my website.
PHP Code:
function remote_file_exists($url)
{
$curl = curl_init($url);
//don't fetch the actual page, you only want to check the connection is ok
curl_setopt($curl, CURLOPT_NOBODY, true);
//do request
$result = curl_exec($curl);
$ret = false;
//if request did not fail
if($result !== false)
{
//if request was ok, check response code
$statusCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($statusCode == 200)
{
$ret = true;
}
}
curl_close($curl);
return $ret;
}
For example this image shows up fine but I can't detect that it exists:
http://www.dailystab.com/blog/wp-con...y-johnson1.JPG
also getimagesize() has the same problem, it can't get the size but the image displays fine.
How can I find if an image will display in the browser without checking by hand?