0

In php, I can create a zip file using:

$zip = new ZipArchive();
$zipname = "somename" . '.zip';
$zip->open($zipname, ZipArchive::CREATE | ZipArchive::OVERWRITE);

and add files to it with

$zip->addFile($pathtodir."filename.bla", "filenameinzip.bla");

or I can add a empty folder to it with:

$zip->addEmptyDir("foldername");

but, is there a way to add a folder which already exists and has sub-content to a zip file directly?

IMPORTANT: the solution in the other thread adds only files in the folder directly to zip, but not the folder itself. I want to keep the structure, meaning the folder should be in the zip file too, not only its sub-content. like:

zipname.zip/foldername/filenameinzip.bla
yangsunny
  • 656
  • 5
  • 13
  • 32
  • There are examples on how to do that in the comments of the add function: http://php.net/manual/en/ziparchive.addfile.php – Gerald Schneider Dec 02 '15 at 08:39
  • 1
    Possible duplicate of [How to zip a whole folder using PHP](http://stackoverflow.com/questions/4914750/how-to-zip-a-whole-folder-using-php) – Gerald Schneider Dec 02 '15 at 08:40
  • @GeraldSchneider: I already read that before I wrote the question, but the answer in the thread adds files directly to the zip, without the folder itself. – yangsunny Dec 02 '15 at 08:53

1 Answers1

0

There is what you need :
1 - other ask in stackoverflow
2 - php documentation

Community
  • 1
  • 1
ElFranchoute
  • 79
  • 2
  • 12