cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

curl with php 4.3.1 http downloads corrupts zip file

From: - - <unicode72_at_hotmail.com>
Date: Thu, 01 Mar 2007 16:34:39 +0100

Hi,

I am downloading a zip file located at a URL. See below code:

$ch = curl_init();

$fp = fopen("test.zip", "w");

curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);

//set error in case http return code bigger than 300
curl_setopt($ch, CURLOPT_FAILONERROR, true);

// allow redirects
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

//hack to make code work on windows
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

//pretend to be IE6 on windows
$useragent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";
curl_setopt($ch, CURLOPT_USERAGENT, $useragent);

// set url to post to
curl_setopt($ch,
CURLOPT_URL,"http://bbs.keyhole.com/ubb/download.php?Number=78983");

//set method to get
curl_setopt($ch, CURLOPT_HTTPGET,true);

curl_exec($ch);
curl_close($ch);
fclose($fp);

Now this works it saves the zip file located at
http://bbs.keyhole.com/ubb/download.php?Number=78983 as zip file test.zip.
The problem is that the zip file is corrupted. It is 0,2 KB to big.

If I download the zip file with my browser it is 56,8 KB (58.177 bytes) and
not corrupted.

If I download it with cURL in php then the zip file is 57,0 KB (58.414
bytes) and corrupted unusable.

I use curl that comes with php 4.3.1.

Anybody got any ideas how to fix this?

_________________________________________________________________
Geef jouw Hotmail kleur met Windows Live Mail! Stap nu over!
http://imagine-windowslive.com/mail/launch/default.aspx?Locale=nl-nl

_______________________________________________
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-and-php
Received on 2007-03-01