Skip to content

Instantly share code, notes, and snippets.

@roshanbh
Last active December 7, 2023 07:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save roshanbh/6111169 to your computer and use it in GitHub Desktop.
Save roshanbh/6111169 to your computer and use it in GitHub Desktop.
Download remote files (on http url ) using curl and PHP
<?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);
}
?>
@AlbinSoft
Copy link

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment