Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

PHP to Download File from Web Server ?

melissa_may1melissa_may1 Posts: 937Member
[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

  • PrzemekG_PrzemekG_ Posts: 595Member
    : [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]
  • spw2000spw2000 Posts: 1Member
    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.