0

I'm working on a function that displays recursively the list of files inside a zip file. A zip file inside another zip file could happen and I want to display its contents like a folder.

I have read carefully this question but I'm yet lost. Ideally It will be perfect if I could get the within zip with getStream and send this stream to another ziparchive::open, but I've not had much this way.

Things I have tried (just to test):

Try 1:

$data = file_get_contents('outer.zip');
$data64 = base64_encode($data);

$zip = new ZipArchive();
$r = $zip->open('data::text/plain;base64,'.$data64);
var_dump($r);

if($r){
    $zip->close();
}

Try 2:

$zip = new ZipArchive();
$r = $zip->open('zip://outer.zip#inner.zip');
var_dump($r);

if($r){
    $zip->close();
}

It will be so slow and bloated if I have to recursively decompress any file to temp just to list the files inside, especially with large files. At this point I'm seeking even shell_exec solutions.

Community
  • 1
  • 1
  • You don't have to decompress both archives. For example you can open outer.zip and extract inner.zip to list its contents. – ggirtsou Feb 16 '14 at 14:12
  • If you want to use a system command use it like this: Decompress innder.zip and then: $ unzip -l inner.zip > outputFile.list – ggirtsou Feb 16 '14 at 14:19
  • @userid53 This is far from what Im looking for cause N levels of zips could be possible, so I always have to extract N-1 levels to list files. Not seems clean enough for me sorry. – Marcos Fernandez Ramos Feb 16 '14 at 14:27
  • Does this help? http://stackoverflow.com/a/2600217/1294631 It shows how to loop through the zip file. By doing this you can detect if the file is an archive and open it and go to whatever level you need to. You need to write your functions to recursively open zip files. – ggirtsou Feb 16 '14 at 14:32
  • @userid53 As I said inside the question, It would be perfect If i could send the getStream stream to another zip->open. The solution you show needs to fread and fwrite every entire file inside a zip just to down the next level. If I want to do so, I'll surely do something like `copy('zip://outer.zip#inner.zip','/tmp/inner.zip');` which seems more clean and fast to me. This is a hard puzzle to solve and I have tried every conventional approach. – Marcos Fernandez Ramos Feb 16 '14 at 14:45

0 Answers0