Create a zip file using PHP class ZipArchive without writing the file to disk?

北慕城南 提交于 2019-12-17 18:05:52

问题


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.


回答1:


Take a look at the following library, it allows creating zip files and returning them as a stream: PHPClasses.org.




回答2:


Try ZipStream (link to GitHub repo, also supports install via Composer).

From original author's website (now dead):

ZipStream is a library for dynamically streaming dynamic zip files from PHP without writing to the disk at all on the server.




回答3:


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.



来源:https://stackoverflow.com/questions/4165289/create-a-zip-file-using-php-class-ziparchive-without-writing-the-file-to-disk

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!