Advertisement
Guest User

output_gz_compressed

a guest
Jan 17th, 2011
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.53 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement