0

The code from this answer simply extracts the contents of a zip file to a folder:

<?php
$zip = new ZipArchive;
$res = $zip->open('file.zip');
if ($res === TRUE) {
  $zip->extractTo('/myzips/extract_path/');
  $zip->close();
  echo 'woot!';
} else {
  echo 'doh!';
}
?>

Is there any simple way (without a foreach loop, per file, and recursively descending into subfolders) to run this operation in reverse, in PHP, so that the original zip file is created again?

The "extract_path" folder must not be included in the zip file, which is why I can't simply use the recursive function linked above.

This would be the PHP equivalent of doing these linux shell commands, which are pretty simple:

cd /myzips/extract_path/
zip /dest/file.zip *

(before anyone comments "Why would you want to do that?", it's because I want to modify a file then recreate the zip file)

Community
  • 1
  • 1
Highly Irregular
  • 38,000
  • 12
  • 52
  • 70
  • I would imagine that the commands you posted are essentially recursively zipping like the answer you linked to? You should be able to modify that answer unless I'm missing something. – Corbin May 22 '12 at 06:12
  • possible duplicate of [How to \[recursively\] Zip a directory in PHP?](http://stackoverflow.com/questions/1334613/how-to-recursively-zip-a-directory-in-php) – Highly Irregular Aug 01 '12 at 04:54
  • The code in the answer to the question I linked to above happened to do the job; I just didn't realise it at the time! – Highly Irregular Aug 01 '12 at 04:55

0 Answers0