Affiliate Marketing
Forum Search

Reply
 
LinkBack Thread Tools Display Modes

  #1 (permalink)  
Old 08-01-04
Registered User
 
Join Date: Aug 2003
Posts: 240
Thanks: 0
Thanked 0 Times in 0 Posts
wibble99 is an unknown quantity at this point
  Downloading a file using PHP

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?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-01-04
Registered User
 
Join Date: Aug 2003
Location: Leicester
Posts: 721
Thanks: 0
Thanked 2 Times in 1 Post
Jeff is an unknown quantity at this point
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 08-01-04
Super Moderator
 
Join Date: Aug 2003
Posts: 2,451
Thanks: 0
Thanked 0 Times in 0 Posts
Rich is an unknown quantity at this point
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 05:34 PM..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 08-01-04
Registered User
 
Join Date: Aug 2003
Posts: 240
Thanks: 0
Thanked 0 Times in 0 Posts
wibble99 is an unknown quantity at this point
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!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #5 (permalink)  
Old 08-01-04
Aquanuke's Avatar
ShagaaDaggaDoo
 
Join Date: Aug 2003
Location: Surrey
Posts: 1,116
Thanks: 0
Thanked 0 Times in 0 Posts
Aquanuke is an unknown quantity at this point
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 08-01-04
Senior Member
 
Join Date: Sep 2003
Posts: 760
Thanks: 0
Thanked 0 Times in 0 Posts
matbennett is an unknown quantity at this point
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 09-01-04
Registered User
 
Join Date: Oct 2003
Location: Norfolk
Posts: 99
Thanks: 0
Thanked 0 Times in 0 Posts
rogerlittin is an unknown quantity at this point
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #8 (permalink)  
Old 09-01-04
Senior Member
 
Join Date: Sep 2003
Posts: 760
Thanks: 0
Thanked 0 Times in 0 Posts
matbennett is an unknown quantity at this point
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 17-01-04
999gi's Avatar
aka Antony
 
Join Date: Aug 2003
Location: Bristol
Posts: 971
Thanks: 0
Thanked 0 Times in 0 Posts
999gi is an unknown quantity at this point
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 19-01-04
Senior Member
 
Join Date: Sep 2003
Posts: 760
Thanks: 0
Thanked 0 Times in 0 Posts
matbennett is an unknown quantity at this point
Some hosts don't allow fopen to run. I *think* this gives a similar error.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #11 (permalink)  
Old 19-01-04
999gi's Avatar
aka Antony
 
Join Date: Aug 2003
Location: Bristol
Posts: 971
Thanks: 0
Thanked 0 Times in 0 Posts
999gi is an unknown quantity at this point
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks