PHP ZipArchive 类允许我使用 open() 方法创建 zip 存档:
mixed ZipArchive::open ( string $filename [, int $flags ] )
然后,我可以将文件添加到此存档,关闭文件,然后像往常一样将其下载到用户的网络浏览器中:
header ('Content-Type: application/zip');
header ('Content-Length: ' . filesize ($filename));
header ('Content-Disposition: attachment; filename="' . $filename . '"');
readfile ($filename);
unlink ($filename);
我的问题:有没有办法避免在服务器硬盘上创建文件、下载该文件然后删除它? IE。是否可以使用 stdout 作为传递给 open() 方法的目标文件名并将存档内容直接写入 stdout ?大致如下:
ZipArchive::open ( STDOUT, ZipArchive::CREATE)
或者我是否坚持需要中间服务器端文件?
最佳答案
“ZipStream 是一个库,用于从 PHP 动态传输动态 zip 文件,而无需在服务器上写入磁盘 服务器。” 链接:https://github.com/maennchen/ZipStream-PHP
关于php - 如何在没有中间服务器端文件的情况下在 PHP 中创建和下载 zip 存档,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35475029/