Page 1 of 1
Check if image loaded from another site?
Posted: Tue Apr 22, 2008 6:41 am
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.
Re: Check if image loaded from another site?
Posted: Tue Apr 22, 2008 6:51 am
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
Re: Check if image loaded from another site?
Posted: Tue Apr 22, 2008 6:57 am
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
Re: Check if image loaded from another site?
Posted: Tue Apr 22, 2008 9:33 am
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.