How do I download files of big sizes from somewhere on the web to the web server with PHP?

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.

Upvotes: 0

Views: 171

Answers (2)

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);
?>

Upvotes: 1

Malax
Malax

Reputation: 9614

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

Upvotes: 0

Related Questions