Unzipping files in PHP with zlib?
Asked Answered
T

3

2

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!

Tallow answered 21/12, 2008 at 19:49 Comment(0)
G
2

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.

Gui answered 21/12, 2008 at 19:59 Comment(0)
T
0

The manual gives a pretty good example.

Terchie answered 21/12, 2008 at 19:53 Comment(0)
D
0

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.

Downrange answered 21/12, 2008 at 19:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.