Unpack files in PHP using zlib?

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

Does anyone know how I can unzip a .gz or .gzip file with a zlib extension in PHP? It would have saved my life!

+1


source to share


3 answers


As written in zlib PHP Binding Introduction :

Version 4.0.4 introduced fopen-wrapper for .gz files, so you can use the special zlib url: to transparently access compressed files using normal file access functions f * (), 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 avoid ambiguities with filenames containing: characters.



Just add fopen

your c file compress.zlib://

and use it as usual.

+2


source


The guide provides a pretty good example.



0


source


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

0


source







All Articles