Results 1 to 11 of 11

 

Thread: Downloading a file using PHP

  1. #1
    Registered User

    Status
    Offline
    Join Date
    Aug 2003
    Posts
    300
    Thanks
    0
    Thanked 1 Time in 1 Post


    Hopefully this is a simple question for anyone that knows PHP - how do I write a simple PHP program that will download a zip file from a specified URL and write it to my server?

    Affiliate Window allows you to easily download the product feed of a merchant by entering an URL in your browser. You're then asked where on your PC you want to save the zip file.

    But I want to do this on my server and have a bit of PHP code that will copy the zip file from the AffiliateWindow URL to a local file.

    Anyone able to give me a quick solution to this?

  2. #2
    Registered User

    Status
    Offline
    Join Date
    Aug 2003
    Location
    Leicester
    Posts
    811
    Thanks
    5
    Thanked 5 Times in 4 Posts
    Do you have to use php?

    The easiest way would be just to run it as a shell script on your server, and use wget to fetch the file. You could automate this by running it as a cron job.

    Would make it easier for us if AW allowed us to download ALL the product feeds in one file, like CJ do, it can be a PITA trying to keep track of so many files.

  3. #3
    Registered User

    Status
    Offline
    Join Date
    Aug 2003
    Posts
    2,448
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is what I use (but not for Awin feeds, yet)
    PHP Code:
    exec("curl -o myfilename.zip httd:remoteserver.com/theirfilename.zip"); 
    That just saves it into the same folder as the php script with the name myfilename.zip. (change the httd: to http://, had to do it to stop the board making a link)

    I then use the PclZip php library to handle extracting files - there could well be easier ways.
    Last edited by Rich; 08-01-04 at 04:34 PM.

  4. #4
    Registered User

    Status
    Offline
    Join Date
    Aug 2003
    Posts
    300
    Thanks
    0
    Thanked 1 Time in 1 Post
    I don't really need to use PHP, but as I needed to then do things with the file afterwards I thought I may as well use it if possible and keep everything in one program. I didn't know about wget, so that was useful.

    While searching for info on wget I also saw talk of cURL. I've not read enough you to see what the difference is but the PHP Rich has provided looks like it's just what I need so I'll give that a test first and see what happens.

    Thanks for your help, it's going to save me a lot of time!

  5. #5
    ShagaaDaggaDoo

    Status
    Offline
    Join Date
    Aug 2003
    Location
    Surrey
    Posts
    1,150
    Thanks
    0
    Thanked 9 Times in 6 Posts
    You could do a simple cron job that does something like this..

    cd /home/www/html/website/
    wget http://domain.com/file.zip
    unzip file.zip

    That basically changes into your working directory, grabs the zip, and unzips it into the current directory.

    You need unzip if its not on your server.
    http://rpmfind.net/linux/rpm2html/se...mit=Search+...

    Nothing fancy, but a simple way to do the job.

  6. #6
    Senior Member

    Status
    Offline
    Join Date
    Sep 2003
    Posts
    768
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Just leaving for the day now, but I have script that does this with Awin feeds already. It's a bit rough, but it works.

    PM me as a reminder and I'll send it over.

  7. #7
    Registered User

    Status
    Offline
    Join Date
    Oct 2003
    Location
    Norfolk
    Posts
    99
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ive got a couple of http client classes that I use for downloading csv files etc.

    PM me with your email if you want and I can send them over.

    Roger.

  8. #8
    Senior Member

    Status
    Offline
    Join Date
    Sep 2003
    Posts
    768
    Thanks
    0
    Thanked 2 Times in 2 Posts
    OK, this one is a bit rough and ready, but it does work. I knocked it together just before Xmas as reading this forum for a couple of month's has persuaded me to try things from the Affiliate end in my "spare" time again.

    I've stripped out a lot of the stuff specific to my setup and added comments in. This version deals with the uncompressed files, rather than zips as the server I have it on cannot uncompress zips:


    PHP Code:
    <?php
    // simple Awin feed saver by MatBennett
    // save as awingrabber.php (or anything) & call using :
    // awingrabber.php?mid=XXX where XXX is the required merchant ID

    // change these for your username & password
    $userName "USERNAME";
    $userPass "PASSWORD";

    // define locations
    $file 'http://products.affiliatewindow.com/csvproductoutput.php?mid='.$mid.'&user='.$userName.'&password='.$userPass.'&nozip=1';
    $destination 'raw/data'.$mid.'.csv'// change this for relative path to your desired server location

    // retrieve & save the zip file
    $fp fopen($file,"r");
    $fp2 fopen("$destination""w");
    while (!
    feof($fp)) {
        
    $buf fread($fp1024);
        
    fwrite($fp2$buf);
    }
    fclose($fp);
    fclose($fp2);

    // file will now be saved as: raw/dataXXX.csv where XXX is the merchant ID

    ?>
    This is very simple and just saves the file to your local server. The version that I use cycles through an array of defined merchants then puts the CSV files into a database, but I thought it probably more useful to provide a "stripped down" version.

    Don't forget to CHMOD 777 the target directory. Hope that it helps.

  9. #9
    aka Antony

    Status
    Offline
    Join Date
    Aug 2003
    Location
    Bristol
    Posts
    966
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Does anyone know what the following error means

    Basically Im running an fopen to try to get files of about 1MB=2MB from a network server
    My host has max_file_size set to 8MB

    Warning: fopen("ftp://...@aftp.linksynergy.com/1623_678251_mp.txt.gz", "r") - Success

    If I Cut and paste the ftp address into my browser the file downloads no problem so its not that.

  10. #10
    Senior Member

    Status
    Offline
    Join Date
    Sep 2003
    Posts
    768
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Some hosts don't allow fopen to run. I *think* this gives a similar error.

  11. #11
    aka Antony

    Status
    Offline
    Join Date
    Aug 2003
    Location
    Bristol
    Posts
    966
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks

    Yes I think it is permissions related (which an area I know even less about).

    I have got stuff working with other networks so its not the hosts fault, so im thinking it must be something like this networks firewall.

    Since I moved from using ASP to php Ive found that the one big thing that bugs me is that their error messages are much more vague - which considering the number of errors I generate is a real pain.



Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. How to make local php file working on remote server?
    By ukyellowpage in forum Programming
    Replies: 10
    Last Post: 21-02-05, 03:24 PM
  2. Replies: 2
    Last Post: 08-08-04, 05:36 PM
  3. PHP - No input file specified. - Problem
    By Barry in forum Programming
    Replies: 1
    Last Post: 02-08-04, 10:57 AM
  4. PHP write file that is writable
    By scifind in forum Programming
    Replies: 3
    Last Post: 30-01-04, 09:12 AM
  5. PHP File Security for Includes
    By bonedome in forum Programming
    Replies: 0
    Last Post: 01-01-04, 08:11 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
To Top

Content Relevant URLs by vBSEO 3.5.0 RC2