$fh = fopen('local-copy-of-files.html','w') or die($php_errormsg);
$c = curl_init('http://www.example.com/files.html');
curl_setopt($c, CURLOPT_FILE, $fh);
curl_exec($c);
curl_close($c);
To pass the cURL resource and the contents of the retrieved page to a
function, set the CURLOPT_WRITEFUNCTION option to
the name of the function:
// save the URL and the page contents in a database
function save_page($c,$page) {
$info = curl_getinfo($c);
mysql_query("INSERT INTO pages (url,page) VALUES ('" .
mysql_escape_string($info['url']) . "', '" .
mysql_escape_string($page) . "')");
}
$c = curl_init('http://www.example.com/files.html');
curl_setopt($c, CURLOPT_WRITEFUNCTION, 'save_page');
curl_exec($c);
curl_close($c);
If none of CURLOPT_RETURNTRANSFER,
CURLOPT_FILE, or
CURLOPT_WRITEFUNCTION is set, cURL prints out the
contents of the returned page.