Download file with php and curl

This is a great tutorial on using cURL in php and downloading a file.

http://phpsense.com/php/php-curl-functions.html

I was able to download a zip file to my web server from a website using this code.

Sample code:

————-

<?php /**
* Initialize the cURL session
*/
$ch = curl_init();
/**
* Set the URL of the page or file to download.
*/
curl_setopt($ch, CURLOPT_URL,
'http://news.google.com/news?hl=en&topic=t&output=rss');
/**
* Create a new file
*/
$fp = fopen('rss.xml', 'w');
/**
* Ask cURL to write the contents to a file
*/
curl_setopt($ch, CURLOPT_FILE, $fp);
/**
* Execute the cURL session
*/
curl_exec ($ch);
/**
* Close cURL session and file
*/
curl_close ($ch);
fclose($fp);
?>

Leave a Reply

Your email address will not be published. Required fields are marked *