-2

I'm having a problem with a folder with an extension .gz in the client side which contains xml files in it. I have to download the folder into local directory then i need to extract the folder.

I was able to download the .gz folder into local, but I'm unable to extract the folder.

I tried using the

ZipArchive::extractto($targetfolder);

But it is not accepting the .gz.

When i search through stack overflow i found only answers for .gz files not for .gz folders.

chembrad
  • 887
  • 3
  • 19
  • 33

2 Answers2

1

Try using PHP's built-in gzfile() function.

This will uncompress the file in 4kB chunks:

function uncompress($srcName, $dstName) {
    $sfp = gzopen($srcName, "rb");
    $fp = fopen($dstName, "w");

    while ($string = gzread($sfp, 4096)) {
        fwrite($fp, $string, strlen($string));
    }
    gzclose($sfp);
    fclose($fp);
}
cassi.lup
  • 1,261
  • 7
  • 23
0

The documentation for ZipArchive doesn't say anything about being able to open gz format files (zip and gz are not the same). You may need to use Zlib to decompress your gz file, and if it's a tar.gz or tgz file, you'll also need something to untar the file.

This question and this newer question discuss how to extract a tar.gz file in PHP.

Community
  • 1
  • 1
Brendan Long
  • 53,280
  • 21
  • 146
  • 188