Check if image loaded from another site?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

Check if image loaded from another site?

Post by ianhull »

If there any php function to check if an image file loaded from another site?

I am setting up a feed for people to send property information from there own websites but if there site is down I dont want the image placeholders to show the dreaded "X".

Any help greatly appreciated.
User avatar
N1gel
Forum Commoner
Posts: 95
Joined: Sun Apr 30, 2006 12:01 pm

Re: Check if image loaded from another site?

Post by N1gel »

You could try using javascript.

There is an onerror Event on an image fired if it fails to load the image.

Your not able to change the source of the imgae but I think last time i used it i set the width and height to 0. But i'm sure there is a better way to handle the error

Check Out

JavaScript onerror Event
ianhull
Forum Contributor
Posts: 310
Joined: Tue Jun 14, 2005 10:04 am
Location: Hull England UK

Re: Check if image loaded from another site?

Post by ianhull »

Thanks N1gel,

I have also just had a thought, do you think file_get_contents() would work?

while I'm looping through the results I could check every image.

Not too sure though, any advise appreciated
Li0rE
Forum Commoner
Posts: 41
Joined: Wed Jun 07, 2006 6:26 am

Re: Check if image loaded from another site?

Post by Li0rE »

yes, you could use file get contents and just do if(!file_get_contents("http://url.to/image")) { }
only problem is, it will have to load the image separately every time to check.

What you could do, however, if you are using a php script to automatically download the image file to your server, is the same thing i did, and do if(!your_function()) { this image is not loading }, and that is killing two birds with one stone.
Post Reply