GZIP extract all files?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

GZIP extract all files?

Post 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?
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: GZIP extract all files?

Post 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);
filippo.toso
Forum Commoner
Posts: 30
Joined: Thu Aug 07, 2008 7:18 am
Location: Italy
Contact:

Re: GZIP extract all files?

Post 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.
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: GZIP extract all files?

Post 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.
Post Reply