remote file question

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
nonsqtr
Forum Newbie
Posts: 1
Joined: Sun Apr 04, 2010 9:35 pm

remote file question

Post by nonsqtr »

Hi all - I'm trying to find a foolproof method for determining whether a file exists on a remote system.

Let's say I'm on myurl.com, and I need to determine whether file xyz.txt exists on otherurl.com

I get some really wacky results from PHP when I use any of the standard file functions, like fopen or file_exists
or any of the other "wrapper" functions. For example, fopen and fread let me read non-existent files! (feof doesn't
seem to work with remote files).

file_exists return FALSE whether or not the file exists on the remote system.... let's see, this is PHP 5 running
on Apache without safe mode and with all the usual accoutrements in place.

Does anyone know of a good way to accomplish this? It's really simple, I don't need the file contents or anything,
I just need a reliable "yes or no" answer for "does the file exist in the location I've specified".

Thanks - your help is greatly appreciated!
User avatar
Architek
Forum Commoner
Posts: 44
Joined: Wed Jul 01, 2009 5:01 am
Location: Portland OR

Re: remote file question

Post by Architek »

just throwing it out there...
Could maybe use ftp_size to validate the file is there by returning the value of the request or its error...
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: remote file question

Post by requinix »

There is no foolproof way to check if a file exists over HTTP.

As Architek suggested you can try another protocol, such as FTP.
Post Reply