Script to save a file on the server

Discussion in 'PHP' started by vipmoney, Aug 23, 2007.

  1. #1
    Does anyone know a script that do this:

    Reads from TXT file available online, and save it on a given dir with a given name.

    Thanks
     
    vipmoney, Aug 23, 2007 IP
  2. webboy

    webboy Peon

    Messages:
    109
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    could you tell us a bit more
    are you saying reads a web page or reads a file from a another hosted server
     
    webboy, Aug 23, 2007 IP
  3. ssanders82

    ssanders82 Peon

    Messages:
    77
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    $text = file_get_contents("fileToRead.txt");

    Are you using PHP5? Use file_put_contents to save $text. Otherwise look at us3.php.net/fwrite
     
    ssanders82, Aug 24, 2007 IP
  4. crazyryan

    crazyryan Well-Known Member

    Messages:
    3,087
    Likes Received:
    165
    Best Answers:
    0
    Trophy Points:
    175
    #4
    ssanders, wouldn't that just get the stuff within the .txt file?
    EDIT: Didn't see the second part, sorry
     
    crazyryan, Aug 24, 2007 IP
  5. vipmoney

    vipmoney Peon

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Hi Guys,

    What I have right now is a page, that loads some data from MySQL database, and retrieves a TXT file using this code at the header:

    
    header("Content-type: ASCII");
    header("Content-Disposition: attachment; filename=".$date."_File.txt"); 
    
    Code (markup):
    This code makes the user able to download a file like this: 20070823_File.txt for example. But this is dynamic data that changes everyday. I could make a cron and start posting all this data into a mysql database by dates, and then create some similar scripts to download specific data from one given date... but I dont want to do that because it would be an extensive database, and I just want the users to be able to download the last 10 txt files from the previous 10 days.

    --> So what I really need, is to make a php script, that is called by a cron everyday or something, and that saves the txt file into some folder on my server.

    My problem is that I don't know how to create a script, that actually saves this txt file into a folder.

    Any idea ?

    thanks for any help ! ;)
     
    vipmoney, Aug 24, 2007 IP
  6. vipmoney

    vipmoney Peon

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Any idea ?

    thanks for any help
     
    vipmoney, Aug 26, 2007 IP
  7. tamilsoft

    tamilsoft Banned

    Messages:
    1,155
    Likes Received:
    78
    Best Answers:
    0
    Trophy Points:
    0
    #7
    Hi,

    Try this script by setting a cron job

    $contents = {data retrieved from mysql db}
    $newfile = time().".txt";
    $folder = "savedfiles";
    $path = $folder."\$newfile";
    $fp = fopen($path,"w");
    fwrite($fp,$contents);
    PHP:
     
    tamilsoft, Aug 26, 2007 IP