Want more features on Pastebin? Sign Up, it's FREE!
Guest

output_gz_compressed

By: a guest on Jan 17th, 2011  |  syntax: PHP  |  size: 0.53 KB  |  views: 25  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  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. }
clone this paste RAW Paste Data