cURL is a great tool to help you connect to remote web sites, making it
easy to post forms, retrieve web pages, or even to download files.Now
I'll show you how you can download a file straight to disk using cURL.
There is however a problem with this code.
If the file you're downloading is quite large, the entire contents must
be read into memory before being written to disk. Doing so can result in
your script breaking down due to exceeding the memory limit.
<?php $url = 'http://www.example.com/a-large-file.zip'; $path = '/path/to/a-large-file.zip';
$fp = fopen($path, 'w'); $ch = curl_init($url);
curl_setopt($ch, CURLOPT_FILE, $fp); $data = curl_exec($ch); curl_close($ch); fclose($fp);
?> That's all there is to it. You can now download files without worrying about exceeding PHP's memory limit.