Skip to content

Instantly share code, notes, and snippets.

@lineker
Created March 9, 2012 00:21
Show Gist options
  • Save lineker/2004304 to your computer and use it in GitHub Desktop.
Save lineker/2004304 to your computer and use it in GitHub Desktop.
PHP: Download remote file CURL
function download_remote_file($file_url, $save_to)
{
//myecho($file_url."---->".$save_to);
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch,CURLOPT_URL,$file_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$file_content = curl_exec($ch);
curl_close($ch);
$downloaded_file = fopen($save_to, 'w');
fwrite($downloaded_file, $file_content);
fclose($downloaded_file);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment