Well, this one seems quite simple, and it is. All you have to do to download a file to your server is:
file_put_contents(\"Tmpfile.zip\", file_get_contents(\
prodigitalson's answer didn't work for me. I got missing fopen in CURLOPT_FILE
more details.
This worked for me, including local urls:
function downloadUrlToFile($url, $outFileName)
{
if(is_file($url)) {
copy($url, $outFileName);
} else {
$options = array(
CURLOPT_FILE => fopen($outFileName, 'w'),
CURLOPT_TIMEOUT => 28800, // set this to 8 hours so we dont timeout on big files
CURLOPT_URL => $url
);
$ch = curl_init();
curl_setopt_array($ch, $options);
curl_exec($ch);
curl_close($ch);
}
}