Download a ZIP using cURL is getting corrupted
<p>I am trying to download a ZIP file from a provided url. When I go to the URL directly, my browser instantly downloads a ZIP file containing a CSV file that I need. But I need an automatic download of this ZIP file. So I was trying to download the ZIP with cURL.</p>

<p>But every time I try to download it with cURL, it seems like the ZIP file is corrupted. I always get the following error when I try to open the ZIP file:</p>

<blockquote>
  <p>No archive found. Archive has an unknown format or is corrupted.</p>
</blockquote>

<p>Also the file has only 59 KB when I download it with cURL, but is larger when I download it with the browser. The ZIP file downloaded with browser has a file size of 2.7 MB.</p>

<p>This is my current code:</p>

<pre><code>ini_set("display_errors", 1);
set_time_limit(0);

$source = "url";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $source);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSLVERSION,3);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0);
curl_setopt($ch, CURLOPT_TIMEOUT, 0);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec ($ch);
$error = curl_error($ch); 

curl_close ($ch);

$destination = "118151_alloy_nl.rar";
$file = fopen($destination, "w+");
fputs($file, $data);
fclose($file);
</code></pre>

<p>Can someone tell me what I am doing wrong?</p>