[ PHPXref.com ] [ Generated: Sun Jul 20 19:13:40 2008 ] [ osCommRes 1.2.0 ]
[ Index ]     [ Variables ]     [ Functions ]     [ Classes ]     [ Constants ]     [ Statistics ]

title

Body

[close]

/includes/functions/ -> gzip_compression.php (source)

   1  <?php
   2  /*

   3  

   4    osCommerce, Open Source E-Commerce Solutions

   5    http://www.oscommerce.com

   6  

   7    Copyright (c) 2003 osCommerce

   8    

   9    osCommRes, Services Online

  10    http://www.oscommres.com

  11  

  12    Copyright (c) 2005 osCommRes

  13  

  14    Released under the GNU General Public License

  15  */
  16    function tep_check_gzip() {
  17      global $HTTP_ACCEPT_ENCODING;
  18  
  19      if (headers_sent() || connection_aborted()) {
  20        return false;
  21      }
  22  
  23      if (strpos($HTTP_ACCEPT_ENCODING, 'x-gzip') !== false) return 'x-gzip';
  24  
  25      if (strpos($HTTP_ACCEPT_ENCODING,'gzip') !== false) return 'gzip';
  26  
  27      return false;
  28    }
  29  
  30  /* $level = compression level 0-9, 0=none, 9=max */

  31    function tep_gzip_output($level = 5) {
  32      if ($encoding = tep_check_gzip()) {
  33        $contents = ob_get_contents();
  34        ob_end_clean();
  35  
  36        header('Content-Encoding: ' . $encoding);
  37  
  38        $size = strlen($contents);
  39        $crc = crc32($contents);
  40  
  41        $contents = gzcompress($contents, $level);
  42        $contents = substr($contents, 0, strlen($contents) - 4);
  43  
  44        echo "\x1f\x8b\x08\x00\x00\x00\x00\x00";
  45        echo $contents;
  46        echo pack('V', $crc);
  47        echo pack('V', $size);
  48      } else {
  49        ob_end_flush();
  50      }
  51    }
  52  ?>


[ Powered by PHPXref - Served by Debian GNU/Linux ]