Page 1 of 1

check a file from other site

Posted: Mon Mar 21, 2005 4:28 am
by yangz
Hi, i found that "file_exists" only check the file from the same server (domain), but now I need to check whether a file from the other site is exist or not...

for example : I placed a product pictures on the site B. now, I build a new site (we called it site A). here in site A, I want to display the picture files from site B into site A... yes, I can easily use <img src='http://www.b.com/picture.jpg'> but I also want to display the "no-pic.jpg" if the file doesn't exist...

any solution for these ?


thanks a lot...

Posted: Mon Mar 21, 2005 4:50 am
by n00b Saibot
A JS approach...

Code: Select all

<img src=&quote;http://www.b.com/picture.jpg&quote; onerror=&quote;this.src='no-pic.jpg'&quote;>
But since everybody may not have enabled JS, you may wnat to look at the other alternatives.

EDIT: I think CURL may be an altrenative for you. look into it. :)

Posted: Mon Mar 21, 2005 7:48 am
by feyd
curl may be the better option indeed, as it allows for you to set a quick timeout. I would suggest caching the results of a remote page query for a while, as performing several on a page will make the page respond quite slow.