skip to Main Content

I am currently facing an issue while trying to decompress a ZIP file that utilizes Deflate64 compression in PHP using the ZipArchive class. The extraction process seems to be working well for regular Deflate compression, but encounters difficulties when dealing with Deflate64.

Here’s an example of a successful extraction using regular Deflate compression:

$zip = new ZipArchive();
$zip->open('deflate.zip');
$zip->extractTo('/tmp/test_extract');
(bool) true

However, when attempting to extract a ZIP file that uses Deflate64 compression, the process fails:

$zip = new ZipArchive();
$zip->open('deflate64.zip');
$zip->extractTo('/tmp/test_extract');
(bool) false

Furthermore, checking if Deflate64 compression is supported using ZipArchive::isCompressionMethodSupported returns false:

ZipArchive::isCompressionMethodSupported(ZipArchive::CM_DEFLATE64);
(bool) false

On the other hand, regular Deflate compression is supported:

ZipArchive::isCompressionMethodSupported(ZipArchive::CM_DEFLATE);
(bool) true

I am reaching out to the community to inquire if there is a known solution or workaround to enable the extraction of ZIP files using Deflate64 compression in PHP’s ZipArchive class. Any insights or code snippets that address this issue would be greatly appreciated.

Thank you in advance for your assistance!

2

Answers


  1. As you have rightly checked, Deflate64 is not supported by the standard PHP ZipArchive

    I would suggest using 7zip

    $command = "7z x deflate64.zip -o/tmp/filename";
    exec($command, $output, $returnVar);
    if ($returnVar === 0) {
        // worked
    } else {
        // failed
    }
    
    Login or Signup to reply.
  2. It looks like the libzip team just don’t want to support deflate64 yet, you can use zlib to inflate each file individually.

    for($i = 0; $i < $zip->numFiles; $i++){
        $st = $zip->statIndex($i);
        if($st['comp_method'] == ZipArchive::CM_DEFLATE64){
            $data = $zip->getFromIndex($i, 0, ZipArchive::FL_COMPRESSED);
            file_put_contents("/tmp/test_extract/$st[name]", gzinflate($data));
        }
    }
    

    Note: You need to create subfolders by yourself.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search