PHP to Download File from Web Server ?

[b][red]This message was edited by melissa_may1 at 2007-4-12 8:7:44[/red][/b][hr]
Hi All:

I'm sure you all can clear up my confusion easily!

What happens between the webserver and the client when the user types a URL that returns a data file? As a result of typing the URL, the browser pops up a "File Download" dialog, and asks "Do you want to open or save this file?"

Here's what I'm trying to do: I want to automate the download of a data file that I get from a webserver daily. Now I manually download the data file to my workstation, then run a program that parses the data file and puts the data into a MySQL database.

I have a webserver with Apache and MySQL and PHP all set up.

I have a PHP script that I use for users on a website to upload files to the server, but that's not what need...

Can I use PHP to do this? Can anyone give me some tips on where to start? I'm so confused!

Thanks!


[purple]Melissa[/purple]


Comments

  • : [b][red]This message was edited by melissa_may1 at 2007-4-12
    : 8:7:44[/red][/b][hr]
    : Hi All:
    :
    : I'm sure you all can clear up my confusion easily!
    :
    : What happens between the webserver and the client when the user
    : types a URL that returns a data file? As a result of typing the URL,
    : the browser pops up a "File Download" dialog, and asks "Do you want
    : to open or save this file?"
    :
    : Here's what I'm trying to do: I want to automate the download of a
    : data file that I get from a webserver daily. Now I manually download
    : the data file to my workstation, then run a program that parses the
    : data file and puts the data into a MySQL database.
    :
    : I have a webserver with Apache and MySQL and PHP all set up.
    :
    : I have a PHP script that I use for users on a website to upload
    : files to the server, but that's not what need...
    :
    : Can I use PHP to do this? Can anyone give me some tips on where to
    : start? I'm so confused!
    :
    : Thanks!
    :
    :
    : [purple]Melissa[/purple]
    :
    :

    If you have a linux workstation, place a script in /etc/cron.daily/ or configure your /etc/crontab to point to your downloading script.


    in PHP:
    [code]
    #!/usr/bin/php
    $data = file_get_contents("http://address.to.data/myData.file");
    file_put_contents("/tmp/myData.file", $data);
    system("php my_data_processing_script.php /tmp/myData.file");
    [/code]

    in shell script:
    [code]
    #!/bin/sh
    wget http://address.to.data/myData.file -O /tmp/myData.file
    php my_data_processing_script.php /tmp/myData.file
    [/code]
  • Very elegant - wish i was working on a Linux workstation - am stuck with a windows one instead but your solution is exactly what i need for my situation - how does your solution translate in to Bill Gates World???

    Forget the scheduling - i am battling to get the code to download a file - all my attempts seem to get a file from the server and put it on the same server.... :(
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories