tags:

views:

24

answers:

0

For some reason when I use my php script to download files via curl it keeps just giving up after a few bytes have been downloaded whereas it was working fine a few weeks ago. The curl error is: transfer closed with xxx bytes remaining to read

I'm running this on localhost but it works fine on my server, I've also tried restarting apache but to no success. This is the code I'm using, can someone please help me? Thanks in advance :)

$fh = fopen("files/" . $title . "/" . $name, "w");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, trim($url));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_FILE, $fh);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-GB; rv:1.9.2) Gecko/20100115 Firefox/3.6 (.NET CLR 3.5.30729)");
curl_exec($ch);
echo curl_error($ch);
curl_close($ch);
chmod("files/" . $title . "/" . $name, 0777);