I am trying to determine if an image exists on a remote server. However, I have tried several methods and cannot make them work.
Now I'm trying to use this:
if (! CheckImageExists ("http://img2.netcarshow.com/ABT-Audi_R8_2008_1024x768_wallpaper_01.jpg")) {
print_r ("DOES NOT EXIST");
} else {
print_r ("DOES EXIST");
};
function CheckImageExists ($ imgUrl) {
if (fopen ($ imgUrl, "r")) {
return true;
} else {
return false;
};
};
But it returns “true” whether the image really exists or not (the above image should, but change it to gibberish, and it will still return “true”). I feel this could be because if the URL does not exist, it will redirect to the website’s homepage. But I do not know how to detect this.
Thanks for any help!
source
share