Perhaps you are looking for something like ZipArchive::addEmptyDir
, which you can use to create an empty directory in a ZIP archive. You can add files to this directory later.
You still need to save the resulting archive to disk ...
$file = tempnam("tmp", "zip"); $zip = new ZipArchive(); $zip->open($file, ZIPARCHIVE::CREATE); $zip->addEmptyDir('newDirectory'); $zip->addFromString('newDirectory/demo.txt', 'file contents'); $zip->close(); // Stream the file to the client header('Content-Type: application/zip'); header('Content-Length: ' . filesize($file)); header('Content-Disposition: attachment; filename="some_archive_file.zip"'); readfile($file); unlink($file);
If you want to transfer the archive without saving the archive at your end, you can try to look at the PHPZip class
source share