ZipArchive unable to extract file

Hello. I’m writing a script to manage Project Gutenberg ebook files. These are mostly text files individually zipped to reduce file size. Well things were going great until my script started having trouble extracting the content of some Zip files. I checked the zip, and I can extract the file from it on my Windows 7 laptop, and I can extract it from the linux shell too. So the zip file is not corrupt.

I tried this on a Raspberry Pi running linux, and assuming that specific OS was the issue, I tried it on an actual linux web server. Both return 0 on ZipArchive:getStream.

Now if I create a new zip file and place the exact same text file in it, then the php code can open a stream into the zip file just fine. It is a problem specific to that zip file.

When I print info about the file in the zip it says it uses Compression Method 6. I think that is the problem. The zip files that it can read have a different compression method (I think 8). getStream is not returning FALSE, but either 0 or NULL. When I check the error code after getStream it is always success and no error.

Here is the code:

$zip=new ZipArchive();
if ($zip->open('WORLD93.ZIP')!==TRUE) {
        echo "Unable to open file.";

//This opens a stream to the first file in the zip for now, and dumps info about it.
for( $i = 0; $i < $zip->numFiles; $i++ ){
        $stat = $zip->statIndex( $i );
        $file=$zip->getStream($stat['name']);  //Returning 0 (not FALSE)


if (!$file) {  //If I test ===FALSE the condition is never met, so $file is either 0 or NULL.
        echo "Unable to open stream.";
        echo $zip->getStatusString(); //Returns no error

while (($line=fgets($file))!==FALSE) {
    echo $line.'<br/>';


Output on the zip file it cannot read:

Array ( [name] => world93.txt [index] => 0 [crc] => 1949831051 [size] => 2638067 [mtime] => 751974948 [comp_size] => 1079984 [comp_method] => 6 )
Unable to open stream.
No error

Is this a known limitation that PHP cannot decompress files in a zip using compression method 6?

PM me a link to that zip file I’ll test it out


Another note is I can decompress the file from the linux shell using unzip. However, I tried using advzip to recompress the file, but that program says “Unsupported compression method on file world93.txt”. So whatever compression method 6 is, it seems to not have universal support for decompressing it.

I think some of these Project Gutenberg files are quite old - like 20+ years - and I don’t know if they have recompressed them at all, so it’s hard to tell what tool was used to compress them and how ancient the algorithm is. I know simply rezipping it under Windows reduces the file size quite a bit, from 1,055k to 887k, so they didn’t compress them very well in the first place.

This is definitely a problem with the zip file. It also fails using fopen(). If I extract the file and create a new zip it works fine. Sorry I couldn’t help.

Sponsor our Newsletter | Privacy Policy | Terms of Service