检查图像是否可访问

i got image url saved in my database.i am using php and mysql.

Some images can be displayed but others are restricted.At the moment restricted image show up broken on my site.

I only which to display non restricted images.

url for image that can be shown is
http://images.icecat.biz/img/gallery/16678932_9061.jpg

restricted image is

http://images.icecat.biz/img/gallery/8622798_7908.jpg

i have tried getimagesize but cant seem to be having any luck.

kind regards

nafri

If you're happy to handle this on the client side, then you could use javascript to deal with this:

You can use handle the onError event to replace the image or do something else in the event that the image cannot be displayed.

See this answer for an example.

file_exists() doesn't work across domains. Server side can be done like:

$url = 'http://images.icecat.biz/img/gallery/16678932_9061.jpg';
$header = get_headers($url, 1);
if(strpos( $header[0],'200') === false){
  // do what ever
}

EDIT: fixed for 200 response. Better use curl though, faster it is