tags:

views:

28

answers:

2

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.

A: 

Use curl for that. PHP must have curl support and you need, obviously, a writeable filesystem.

Malax
Doesn't something needs to be changed in the php.ini?
A: 

Could this do a good job?

<?php
ini_set(max_execution_time, 0);

$the_link = $_GET['url'];

$ch = curl_init($the_link);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT  5.1; .NET CLR 1.1.4322;)");
curl_setopt($ch, CURLOPT_COOKIEJAR, '/tmp/cookies.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, '/tmp/cookies.txt');
$the_file = curl_exec($ch);
curl_close($ch);

$hdl = fopen("file", 'w');  
fwrite($hdl, $the_file);
fclose($hdl);
?>