使用 PHP 类 ZipArchive 创建 zip 文件而不将文件写入磁盘?
我想使用 ZipArchive (或本机 PHP 类)在内存中创建一个 zip 文件,并将文件的内容读回客户端。这可能吗?如果是这样,怎么办?
我想要在此应用程序中压缩的文件总共最大为 15 MB。我认为我们的记忆力应该保持良好状态。
I would like to create a zip file in memory using a ZipArchive (or a native PHP class) and read the content of the file back to the client. Is this possible? If so, how?
The files that I want to zip in this application are a maximum of 15 MB total. I think we should be in good shape memory-wise.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
尝试 ZipStream (链接到 GitHub 存储库,也支持通过 作曲家)。
来自原作者的网站(现已死亡):
Try ZipStream (link to GitHub repo, also supports install via Composer).
From original author's website (now dead):
感谢 Frosty Z 提供的优秀库 ZipStream-PHP。我们有一个用例,用于上传一些数量和大小都较大的 zip 文件到 S3。官方文档没有提到如何上传到S3。
因此,我们有一个想法,将 ZipStream 输出创建的 zip 直接流式传输到 S3,而无需在服务器上创建 zip 文件。
这是我们提出的工作示例代码:
Thanks to Frosty Z for the great library ZipStream-PHP. We have a use case to upload some large zip files in quantity and size to S3. The official documentation does not mention how to upload to S3.
So we've had an idea to stream the zip created by ZipStream output directly to S3 without creating the zip file on the server.
Here is a working sample code that we came up with:
看一下下面的库,它允许创建 zip 文件并将它们作为流返回: PHPClasses.org。
Take a look at the following library, it allows creating zip files and returning them as a stream: PHPClasses.org.
还有另一个话题讨论这个:
使用 PHP 操作内存中的存档(无需在磁盘上创建临时文件)
nettle 建议使用 phpmyadmin。我认为这是一个相当可靠的解决方案。
仅供参考 zip.lib.php 不再存在,它已被同一库/文件夹中的 ZipFile.php 替换。
There is another thread talking about this:
Manipulate an Archive in memory with PHP (without creating a temporary file on disk)
nettle has suggested to use zip.lib.php from phpmyadmin. I think this is a rather solid solution.
FYI zip.lib.php does not exist anymore, it has been replace by ZipFile.php in the same libraries/ folder.