title: download and save a gzip file using php curl
body: <p>I am trying to download a gzip file using curl and php and saving it in a specified location. Below is the code that I am using but everytime it's saving an empty file allthough the gzip file that it's downloading is proper</p>
  
  <pre><code>$file_zip = 'abc.gz'
  $fp = fopen("$file_zip", "w"); 
  $request = curl_init();
  $headers = array('Content-type: application/x-gzip','Connection: Close');
  curl_setopt($request, CURLOPT_URL, $url);
  curl_setopt($request, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($request, CURLOPT_TIMEOUT, 0);
  curl_setopt($request, CURLOPT_CONNECTTIMEOUT,0);
  curl_setopt($request, CURLOPT_HTTPHEADER,$headers);
  curl_setopt($request, CURLOPT_FAILONERROR, true);
  curl_setopt($request, CURLOPT_FOLLOWLOCATION, true);
  curl_setopt($request, CURLOPT_AUTOREFERER, true);
  curl_setopt($request, CURLOPT_BINARYTRANSFER,true);
  
  curl_setopt($request, CURLOPT_FILE, $fp);
  
  $zipFile = curl_exec($request);
  </code></pre>