curl-and-php
Downloading a file instead of the web page
Date: Mon, 25 Mar 2002 22:00:46 +0000
Greetings,
I am trying to use curl with PHP to download a file from a web site. The
problem is that the file is downloaded from the browser rather than echoed
to the screen, and curl is saving the webpage displayed instead of the file
to my server. The file to be saved sends the following headers:
Content-Type: application/text; name="phpa.keys"
Content-Disposition: inline; filename="phpa.keys"
So, is there any way to get curl to snatch this file instead of the web
page? The form in question is the second one @
http://php-accelerator.co.uk/activate.php. The relevant part of the PHP
file I'm using is (error handling removed for brevity):
<?php
$ch = curl_init('http://www.php-accelerator.co.uk/activate.php');
$domains = "www.test.com\ntest.com\nfoobar";
###print "These are the domains you are sending:\n\n$domains\n\n";
$submit = array('formname' => 'register2',
'domain2' => $domains
);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $submit);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_USERAGENT, 'phpa key bot by Peter');
// curl_setopt($ch, CURLOPT_REFERER, '/activate.php');
curl_setopt($ch, CURLOPT_VERBOSE, 1);
$output = curl_exec($ch);
// Write the keys to the file... or echo them :-)
print "Your registration file is:\n";
print $output;
?>
I am running this using the cgi binary (and yes, the curl functions do
work) but assume that mod_php wouldn't make any difference.
Any advice gratefully received.
Thanks in advance,
Peter.
--oOo--
Narrow Gauge on the web - photos, directory and forums!
http://www.narrow-gauge.co.uk
--oOo--
Glenbranter - Scottish narrow gauge in 009
http://glenbranter.narrow-gauge.co.uk
--oOo--
Received on 2002-03-25