Created
May 31, 2021 18:12
-
-
Save dilakv/2841c8e26219ce4d6a4d9beae5dd4faf to your computer and use it in GitHub Desktop.
Download a file from server using php and curl
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 | |
// create a new cURL resource | |
$ch = curl_init(); | |
$URL = "HTTP - Direct-Link"; | |
$filename = "nameofthefile.extension"; | |
// set URL and other appropriate options | |
curl_setopt($ch, CURLOPT_URL, $URL); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
// grab URL and pass it to the browser | |
$out = curl_exec($ch); | |
// close cURL resource, and free up system resources | |
curl_close($ch); | |
$fp = fopen($filename, 'w'); | |
fwrite($fp, $out); | |
fclose($fp); | |
echo "Hecho!"; | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment