I have the need to download a file from a server. The file is "http://www.moneyextra.com/stocks/ftse100/ftse100.tsv". I want to copy it to a local directory on my PC where i can then parse the delimited file and transfer the data to a database.

I'm sure this should be simple to do but how do i get the file from that address automatically without having to do a manual download. Is there a set of PHP commands I can code that will do this. I can do all the parsing fine and the database transfer too is no problem. I just want to copy the file to my local directory!!

Thanks for any help anyone can give me!

Regards,

Andrew Easter

    So long as the remote url is [url]http://,[/url] and not [url]https://,[/url] you can actually fopen the file as though it were local, ie:

    
    if (($fp = fopen("http://www.moneyextra.com/stocks/ftse100/ftse100.tsv","r")) == NULL) {
      print "Failed to open remote location.<BR>\n";
    } else {
     //do whatever you like -- treat as though it were a local file
    }
    

    Starting with php 4.3.0, you will be able to use [url]https://[/url] as a method also, IF you have compiled with openssl support.

    Originally posted by andyeaster
    I have the need to download a file from a server. The file is "http://www.moneyextra.com/stocks/ftse100/ftse100.tsv". I want to copy it to a local directory on my PC where i can then parse the delimited file and transfer the data to a database.

    I'm sure this should be simple to do but how do i get the file from that address automatically without having to do a manual download. Is there a set of PHP commands I can code that will do this. I can do all the parsing fine and the database transfer too is no problem. I just want to copy the file to my local directory!!

    Thanks for any help anyone can give me!

    Regards,

    Andrew Easter

      Thanks for your help guys. I have sorted it out from your advice. Nice one!

      Andrew

        Write a Reply...