check a file from other 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
yangz
Forum Newbie
Posts: 1
Joined: Mon Mar 21, 2005 4:19 am

check a file from other site

Post 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...
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post 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. :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Post Reply