Created
April 20, 2012 06:33
-
-
Save liconti/2426607 to your computer and use it in GitHub Desktop.
PHP dowload file (following redirects)
This file contains 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 download_file($url, $filename){ | |
$ch = curl_init($url); | |
if (is_writable(dirname($filename))) { | |
$fp = fopen($filename, "w"); | |
curl_setopt($ch, CURLOPT_FILE, $fp); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); | |
curl_exec($ch); | |
curl_close($ch); | |
fclose($fp); | |
} else { | |
echo 'The file ($filename) is not writable'; | |
die(); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment