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.";
exit();
}
//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)
print_r($zip->statName($stat['name']));
break;
}
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
$zip->close();
exit();
}
while (($line=fgets($file))!==FALSE) {
echo $line.'<br/>';
}
$zip->close();
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?