Forum Moderators: coopster

Message Too Old, No Replies

FTP > File Exists?

         

jazzle

2:01 pm on Nov 7, 2005 (gmt 0)

10+ Year Member



Hi,
I am downloading the latest file from an FTP server.

Fortunately the files are named with the date:
20051107_blah.csv (Created every working week day.

I have some simple code which connects to the server, moves to the right directory, then creates the filename from the current date.
It first tries 'today', then creates the filename for the previous day, etc. within a loop limiting it to a week. When a file has been successfully copied it then continues as desired.

The problem is that my code outputs errors, visible to the user, and naturally I don't want them to see.

Is there a way to see if a file exists without getting these visible errors?

adb64

2:19 pm on Nov 7, 2005 (gmt 0)

10+ Year Member



If you don't want visitors to see errors from PHP prefix the command with a @ sign, eg:

$fp = @fopen($Filename,"r");

When the file can not be opened, $fp contains an invalid handle and no output is send to the visitor.

This @ method can be used on every PHP function to prohibit error messages to be sent to the visitor.

jazzle

2:32 pm on Nov 7, 2005 (gmt 0)

10+ Year Member



perfect, thank you!