Skip to content

Instantly share code, notes, and snippets.

@GerBawn
Created August 13, 2015 01:35
Show Gist options
  • Save GerBawn/83cede8437432b939461 to your computer and use it in GitHub Desktop.
Save GerBawn/83cede8437432b939461 to your computer and use it in GitHub Desktop.
download something from Internet
<?php
function downloadFile($url, $saveName){
set_time_limit(0);
// create a new cURL resource
$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_AUTOREFERER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// grab URL and pass it to the browser
$opt = curl_exec($ch);
// close cURL resource, and free up system resources
curl_close($ch);
$handle = fopen($saveName, 'wb');
fwrite($handle, $opt);
fclose($handle);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment