Download file or web page using PHP cURL
I am discussion how to use cURL function of php to download a web page and save it .
A typical PHP cURL usage follows the following sequence of steps.
curl_init – Initializes the session and returns a cURL handle which can be passed to other cURL functions.
curl_opt – This is the main work horse of cURL library. This function is called multiple times and specifies what we want the cURL library to do.
curl_exec – Executes a cURL session.
curl_close – Closes the current cURL session.
Below are some examples which should make the working of cURL more clearer.
The below PHP code uses cURL to download Google’s RSS feed.
<?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); ?>
SO enjoy php cURL function to save remote file.
thanks






