Last active
December 7, 2023 07:31
-
-
Save roshanbh/6111169 to your computer and use it in GitHub Desktop.
Download remote files (on http url ) using curl and PHP
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 | |
//$file - should contain full url | |
// $newFileName - full physical path directory with file name | |
function getFile($file, $newFileName) | |
{ | |
$err_msg = ''; | |
echo "<br>Attempting message download for $file<br>"; | |
$out = fopen($newFileName, 'wb'); | |
if ($out == FALSE){ | |
print "File not opened<br>"; | |
exit; | |
} | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_FILE, $out); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
curl_setopt($ch, CURLOPT_URL, $file); | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); | |
curl_exec($ch); | |
echo "<br>Error is : ".curl_error ( $ch); | |
curl_close($ch); | |
fclose($out); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks.