Created
August 27, 2020 05:50
-
-
Save mrmmg/1defa2f8a4f6919c2ec08b025f69aa1d to your computer and use it in GitHub Desktop.
Using PHP Curl to download large file
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
$host = "http://example.com/download.txt"; | |
$output_filename = "download.txt"; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $host); | |
curl_setopt($ch, CURLOPT_VERBOSE, 1); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_AUTOREFERER, false); | |
curl_setopt($ch, CURLOPT_REFERER, "https://getmyfile.xyz"); | |
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
curl_exec($ch); | |
curl_close($ch); | |
// the following lines write the contents to a file in the same directory (provided permissions etc) | |
$fp = fopen($output_filename, 'w'); | |
fwrite($fp, $result); | |
fclose($fp); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment