如何压缩文件夹然后将其解压缩到其他位置?
我正在开发一个网站,该网站下载用户从我们的其他服务器上传的文件夹,但首先我们必须压缩该文件夹 - 如何压缩整个文件夹的内容?
I'm working on a site which downloads folders users upload from our other server, but first we have to zip that folder - how do I zip up a whole folders' contents?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看
ZipArchive
。如果您遇到特定问题,请编辑您的问题,我会尽力提供更多帮助。您可能没有安装ZipArchive
- 如果没有,请按照 安装说明。您需要的功能:
open
< /a>:打开 zip 存档(您需要使用标志ZIPARCHIVE::CREATE
)。addEmptyDir
:创建一个空的zip 存档中可以添加文件的目录。addFile
:添加文件将您的文件系统添加到存档中。您可能希望通过调用此函数来运行要添加文件的文件夹。close
:关闭zip写入完毕后进行存档。extractTo
:获取文件从 zip 存档中取出将它们放在某处示例代码:
Take a look at the documentation for
ZipArchive
. If you've got a particular problem with it, edit your question and I'll try to be more helpful. You may not haveZipArchive
installed - if not, follow the installation instructions.Functions that you'll need:
open
: Opens the zip archive (you'll want to use the flagZIPARCHIVE::CREATE
).addEmptyDir
: Creates an empty directory in the zip archive that you can add files to.addFile
: Adds a file on your filesystem to the archive. You'll presumably want to run through the folder you wish to add files from calling this function.close
: Close the zip archive when you're done writing to it.extractTo
: Get the files out of the zip archive to put them somewhereSample code: