你的代码我不是很懂,我觉得应该在apache的配置文件中注册mime类型
text/zip gzip

解决方案 »

  1.   

    如果在linux中,编译php的时候要加参数“--with-zlib=yes”。这样php才可以支持gzip压缩输出。如果在windows平台上,在php.ini中的extension中打开“;extension=php_zlib.dll”把分号去掉。如果失败,则下载php for windows的完全包。如果不打开这个模块,当然就会出现你的问题了。
      

  2.   

    多谢各位答复!这是一段将页面压缩书出的代码,所以使用了zlib库中的函数zlib当然支持了,否则我这段代码汇报错的!而且我还使用了function_exists('gzcompress')监测这个压缩函数的存在。问题是在浏览器这边,它不给压缩输出后的页面解压缩显示,而是当作了一个文件下载,问题可能是出在header("Content-Encoding: $ENCODING");函数里,大家再帮忙想想办法吧,真的很急,我试过无数方法都不行了。
      

  3.   

    header里加上输出:
    Content-Type: text/html
      

  4.   

    给你个例子:把你的代码加到中间省略处。
    <?
    if (function_exists("ob_start") and function_exists("crc32") and function_exists("gzcompress") and !$nozip){
    ob_start();
    }
    ?>
    <html><head>
    <meta content="text/html; charset=windows-1252" http-equiv="Content-Type">
    <meta http-equiv="MSThemeCompatible" content="Yes">
    <link rel="stylesheet" href="../include/style.css">
    <body leftmargin="10" topmargin="10" marginwidth="10" marginheight="10">
    .
    .
    .
    .
    </BODY></HTML>
    <?php if (function_exists("ob_start") and function_exists("crc32") and function_exists("gzcompress") and !$nozip) {
        if (strpos(" ".$HTTP_ACCEPT_ENCODING,"x-gzip")) {
          $encoding = "x-gzip";
        }
        if (strpos(" ".$HTTP_ACCEPT_ENCODING,"gzip")) {
          $encoding = "gzip";
        }    if ($encoding) {
        $text = ob_get_contents();
    ob_end_clean();      header("Content-Encoding: $encoding");      $size = strlen($text);
          $crc = crc32($text);      $returntext = "\x1f\x8b\x08\x00\x00\x00\x00\x00";
          $returntext .= substr(gzcompress($text,$level),0,-4);
          $returntext .= pack("V",$crc);
          $returntext .= pack("V",$size);      echo $returntext;
          exit;
        }
      }
      

  5.   

    上面的$nozip为控制参数,可以先去掉不要。
      

  6.   

    echo $ENCODING看看最后到底输出的是什么