Check whether the image returned is the image requested

I’ve got a web page where I get image URLs in a data feed, but not all the image URLs actually point to a file (and they’re on external servers that I don’t control). I’m trying to write a surefire method of determining whether the file exists. In most cases @fopen or getimagesize works, but I have some cases where the image file doesn’t exist and the server passes back an “image not found” image, so both @fopen and getimagesize are reacting as if the original image is there. What I’m wondering is if there’s a way to check the name of the image file being passed back and compare it to the original requested filename.

I wanted to add that I also tried curl_getinfo, which interestingly is telling me that there were 0 redirects. And yet when I plug the original image URL into my browser directly, I get redirected to a different image.

OK, figured out a solution. If I get the HTTP code using get_headers, I can check for a 301 code, in which case I know the image has been switched.

Sponsor our Newsletter | Privacy Policy | Terms of Service