Page 1 of 1

GZIP extract all files?

Posted: Sat Aug 09, 2008 12:24 am
by JAB Creations
I've been reading the GZIP functions on php.net and frankly I'm still a bit baffled at how to extract all the files from a GZIP archive? Could someone please point me in the correct direction?

Re: GZIP extract all files?

Posted: Sat Aug 09, 2008 1:26 am
by JAB Creations
Looks like read is what I want (why it's not called extract is beyond me)...

This script I just wrote is returning true though no files have been extracted, what am I doing wrong?

Code: Select all

$filename = "test.gz";
$zd = gzopen($filename, "r");
if (!$zd) {echo 'OPEN: did not work?<br />';}
else {echo 'OPEN: worked?<br />';}
 
$contents = gzread($zd, 100000);
if (!$contents) {echo 'READ: did not work?';}
else {echo 'READ: worked?';}
gzclose($zd);

Re: GZIP extract all files?

Posted: Sat Aug 09, 2008 5:02 am
by filippo.toso
A GZIP archive contains only 1 file / stream of data. To insert multiple files/directories into a GZIP file they must be "packed" using a tool like TAR.

In your code, the $contents variables contains the first 100000 uncompressed bytes of the test.gz file.

Re: GZIP extract all files?

Posted: Sat Aug 09, 2008 6:23 am
by JAB Creations
Thanks, I guess I'll look for ZIP support then. I've really only used GZIP with access logs (server generated of course) so I never knew about the one file limitation. GZIP's one file limitation makes no sense, especially if it's been around for so long.