views:

1875

answers:

3

My web site is hosted at Dreamhost and there they only get zlib installed along with PHP. I couldn't figure out how to unzip files with the commom methods from this extension as described here : http://php.net/zlib

Does anyone knows how can I unzip a .gz or .gzip file with zlib extension on PHP? That would save my life!

A: 

The manual gives a pretty good example.

JW
A: 

GZip and Deflate are explained in RFC 1952 (GZip) and RFC 1950 (Deflate). GZip is just Deflate with a header described there, so you can parse that header to detect where the zLib stream is and decompress it with zLib routines.

schnaader
+1  A: 

As written in zlib's PHP binding introduction:

Version 4.0.4 introduced a fopen-wrapper for .gz-files, so that you can use a special zlib: URL to access compressed files transparently using the normal f*() file access functions if you prefix the filename or path with zlib: when calling fopen(). [...] In PHP 4.3.0, zlib: has been changed to compress.zlib:// to prevent ambiguities with filenames containing ':' characters.

Simply fopen your file with compress.zlib:// prepended, and use it as normal.

strager