Php 通过CloudFlare下载gzip文件

Php 通过CloudFlare下载gzip文件,php,http-headers,gzip,cloudflare,Php,Http Headers,Gzip,Cloudflare,我有一个PHP文件保护器脚本: .htaccess RewriteEngine on RewriteRule ^(.*).(zip|tgz)$ ../wp-file-protector.php?file=$1.$2 [QSA] wp-file-protector.php <?php global $wpdb; /** Make sure that the WordPress bootstrap has run before continuing. */ require( dirname

我有一个PHP文件保护器脚本:

.htaccess

RewriteEngine on
RewriteRule ^(.*).(zip|tgz)$ ../wp-file-protector.php?file=$1.$2 [QSA]
wp-file-protector.php

<?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->ID > 0){

  $order = $_GET['order'];
  $items = new_get_order_by_id_and_user($order, $current_user->ID);
  if($items != false){
    $file_enabled = true;
//Some authentication
    $filepath = dirname(__FILE__).'/../downloads/'.$_GET['file'];
    if($file_enabled && 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);
    }
  }
}
这也不行。当我选择在firefox中保存时,它会告诉我何时打开该文件。当我选择open时,我得到了一个没有扩展名的文件,但它似乎是tar,因为我可以深入目录

header("Content-type: application/x-gzip");