Created
August 13, 2015 01:35
-
-
Save GerBawn/83cede8437432b939461 to your computer and use it in GitHub Desktop.
download something from Internet
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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