title: Download gzipped file through CloudFlare
body: <p>I have a PHP file protector script:</p>
  
  <p>.htaccess</p>
  
  <pre><code>RewriteEngine on
  RewriteRule ^(.*).(zip|tgz)$ ../wp-file-protector.php?file=$1.$2 [QSA]
  </code></pre>
  
  <p>wp-file-protector.php</p>
  
  <pre><code>&lt;?php
  
  global $wpdb;
  /** Make sure that the WordPress bootstrap has run before continuing. */
  require( dirname(__FILE__) . '/wp-load.php' );
  
  
  $current_user = wp_get_current_user();
  if ($current_user-&gt;ID &gt; 0){
  
    $order = $_GET['order'];
    $items = new_get_order_by_id_and_user($order, $current_user-&gt;ID);
    if($items != false){
      $file_enabled = true;
  //Some authentication
      $filepath = dirname(__FILE__).'/../downloads/'.$_GET['file'];
      if($file_enabled &amp;&amp; file_exists($filepath)){
        $filename = basename($filepath);
        $extension = end(explode('.', $filename));
        ob_clean();
        // http headers for zip downloads
        header("Pragma: public");
        header("Expires: 0");
        header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
        header("Cache-Control: public");
        header("Content-Description: File Transfer");
        if($extension == 'tgz'){
          header("Content-Type: application/gzip");
        }else{
          header("Content-type: application/octet-stream");
        }
        header("Content-Disposition: attachment; filename=\"".$filename."\"");
        header("Content-Transfer-Encoding: binary");
        header("Content-Length: ".filesize($filepath));
        ob_end_flush();
        @readfile($filepath);
      }
    }
  }
  </code></pre>
  
  <p>I works fine with zipped and other files. The problem appears with gzipped files. I got unexpected results (also different results for Firefox download and open action).</p>
  
  <p>I think I need some good header for the gzipped files. What should I use?</p>
  
  <p>Also good to know that the request is running through the Cloudflare service, so maybe I should send out some header, which tells cloudflare server to not to gzip it.</p>
  
  <p>I'm stuck :(</p>
  
  <h2>Update #1</h2>
  
  <pre><code>header("Content-type: application/x-gzip");
  </code></pre>
  
  <p>This also doesn't work. When I choose save in firefox, it tells when opening that corrupted. When I choose open, I got a file without extension, but it seems tar as I can go deeper into the dir.</p>