SHARE
TWEET

output_gz_compressed

a guest Jan 17th, 2011 28 Never
  1. function output_gz_compressed($contents)
  2. {
  3.   if (stripos($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip') !== False)
  4.   {
  5.     $contents = gzcompress($contents, 9);
  6.     //remove old crc
  7.     $contents = substr($contents, 0, strlen($contents) - 4);
  8.  
  9.     header('Content-Encoding: gzip');
  10.     header('Content-Length: ' + strlen($contents));
  11.  
  12.     //gzip header
  13.     echo "\x1f\x8b\x08\x00\x00\x00\x00\x00";
  14.     echo $contents;
  15.     echo pack('V', crc32($contents));
  16.     echo pack('V', strlen($contents));
  17.   }
  18.   else
  19.     echo $contents;
  20. }
RAW Paste Data
Top