有没有类似ZipArchive的东西,但用于发送zip下载而不在磁盘上生成文件


Is there anything like ZipArchive but for sending the zip for download without generating the file on disk?

我想用PHP创建一个zip文件,并使用header()函数使其可下载,而无需将文件保存在服务器上。但我认为内置的ZipArchive无法做到这一点。我发现了一些可以的,但它们都是从现有文件中添加文件的,我需要像ZipArchive:addFromString()那样添加它。

有人知道一个具有这种能力的类或东西吗?

根据PHP压缩流文档ZipArchive注册zip://流包装器。虽然我从未使用过zip://流,但您可以查看zip.compress是否有效。您可以根据此处的另一个示例构建测试。

gzip为文件执行此操作。对于归档,您可以使用gzip和tar,如下所示。

tar -cz  thedir 

这就是使用zip的方法。

zip - file1.txt file2.txt