Выше приведен пример (продигиталсон) кода wchih не работает (причина: отсутствует fopen в CURLOPT_FILE - http://www.webdeveloper.com/forum/showthread.php?268299-RESOLVED-PHP- script-for-a-cronjob-download-file-unpzck-run-another-php-script ). Я не могу добавить комментарий там, потому что у меня слишком низкое количество очков, поэтому ниже я даю рабочий пример (он также работает для «локального url»):
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);
}
}