Example of how to decompress a file or string using gzip in php
- /**
- * Php custom gzdecode decompress the gzip file
- * Edit bbs.it-home.org
- */
- If (! Function_exists ('gzdemo ')){
- Function gzdecode ($ data ){
- $ Flags = ord (substr ($ data, 3, 1 ));
- $ Headerlen = 10;
- $ Extralen = 0;
- $ Filenamelen = 0;
- If ($ flags & 4 ){
- $ Extralen = unpack ('v', substr ($ data, 10, 2 ));
- $ Extralen = $ extralen [1];
- $ Headerlen + = 2 + $ extralen;
- }
- If ($ flags & 8) // Filename
- $ Headerlen = strpos ($ data, chr (0), $ headerlen) + 1;
- If ($ flags & 16) // Comment
- $ Headerlen = strpos ($ data, chr (0), $ headerlen) + 1;
- If ($ flags & 2) // CRC at end of file
- $ Headerlen + = 2;
- $ Unpacked = @ gzinflate (substr ($ data, $ headerlen ));
- If ($ unpacked = FALSE)
- $ Unpacked = $ data;
- Return $ unpacked;
- }
- }
- ?>
Call:
- $ F = @ file_get_contents (http://bbs.it-home.org );
- Echo gzdecode ($ f );
- ?>
|