Forum Moderators: coopster

Message Too Old, No Replies

Get TXT file from another server

         

MarRup

11:14 pm on Aug 5, 2004 (gmt 0)

10+ Year Member



Hi,
I have a link to a txt file on a website and I would like to download it from time to time to my server. Which functions should I use in php? How to do that?

MarRup

11:17 pm on Aug 5, 2004 (gmt 0)

10+ Year Member



Well I forgot to tell that the file should be saved in the same folder as my downloadscript and that the file is around 26MB (if that matter).

jatar_k

11:18 pm on Aug 5, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



are you looking to just copy it or does it need to be processed in some way?

MarRup

11:36 pm on Aug 5, 2004 (gmt 0)

10+ Year Member



I will process it, but it is a cvs file so I know how to do it.

But I just don't know how to copy it (download it) and put it in my folder! (never done that before)

jatar_k

11:55 pm on Aug 5, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you could use readfile [ca2.php.net] and then fopen locally and save it that way.

You could use fopen and then read it and write it line by line.

You could use ftp functions if you have ftp access to that file.

You could probably even use curl to grab it if you wanted.

For files on other servers I often fopen, process and save all in the same script.

MarRup

12:00 am on Aug 6, 2004 (gmt 0)

10+ Year Member



Thanks for the suggestions. I just don't really want to use fopen, because the file is 25MB at least. See what I will use. I will think of the different options I have.

TheBlueEyz

1:10 am on Aug 6, 2004 (gmt 0)

10+ Year Member



Your best bet is to open the socket using fopen - fopen works regardless of file size.

The limitation is the MODE used to retrieve the file.

Seems a good suggestion appears to be using FGETS instead of fread. Since it's a text file, you probably don't need a binary-safe read anyway.

[us2.php.net...]

Search for the word "large" on the page.