Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How do I download files of big sizes from somewhere on the web to the web server with PHP? Also, what should be allowed on the server in order to make this happen? Thanks.

share|improve this question

You need CURL module installed on PHP.

Then create a folder on the server to save the downloaded files and set write permissions so that the webserver can write to that folder. Then just modify this PHP-script to download whatever file you want, just change the URL and the target filename (my example downloads Opera 10 disk image for Mac):

$url = '';
$filename = 'temp/opera.dmg';
$fp = fopen($filename,'w+');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

The CURLOPT_TIMEOUT sets the maximum time CURL can use to download the file, note also that if the downloads take long time to finish, you might need to modify the PHP execution timeout in php.ini.

share|improve this answer
50 mins or secs? – ThisIsMyselfFromRussia Sep 18 '09 at 13:41
How do I know how many secs it will need??? – ThisIsMyselfFromRussia Sep 18 '09 at 13:47
The timeout is in secs. And you just need to calculate the maximum time the download might take. Just estimate your download speed, divide the maximum filesize with that and add some for safety and that is the timeout value you need. – Raynet Sep 18 '09 at 14:02
And what if I cut out the timeout option? Would it hurt? – ThisIsMyselfFromRussia Sep 18 '09 at 14:34
Only 2M out 10M have been downloaded. 2M is set as upload_max_filesize in php.ini on the server. How to change? – ThisIsMyselfFromRussia Sep 18 '09 at 14:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.