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.
views:
28answers:
2
A:
Use curl for that. PHP must have curl support and you need, obviously, a writeable filesystem.
Malax
2009-09-18 11:29:41
Doesn't something needs to be changed in the php.ini?
2009-09-18 11:33:08
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);
?>