不使用 exec 创建 zip 或 tar.gz 存档
有没有安全的方法可以在不使用 exec 命令的情况下从 php 创建 zip 存档或 tar.gz ?
谢谢
Is there is any safe way to create a zip archive, or tar.gz from php without using exec command ?
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
如果您想创建 tar.gz 并且使用 PHP 5.3+,则可以使用 PharData 类:
If you want to create tar.gz and you are using PHP 5.3+, you can use PharData class:
您可以使用 PHP 的 Zip 类来创建 zip 文件,并且 ZLib 创建 gzip 文件。
创建
.zip
文件:创建
.gz
文件:You can use PHP's Zip class to create zip files, and ZLib to create gzip files.
Creating a
.zip
file:Creating a
.gz
file:请改用系统命令
http://php.net/manual/en/function.system。 php
请注意注释部分如何防止恶意输入。
编辑:使用 ZipArchive 类通过 open() 命令 http: //www.php.net/manual/en/class.ziparchive.php
Use the system command instead
http://php.net/manual/en/function.system.php
Pay attention to the notes section on how to protect from malicious input.
EDIT: Use the ZipArchive class to create a new zip via the open() command http://www.php.net/manual/en/class.ziparchive.php
有一种非常简单的方法可以直接在 PHP 中创建 Tar 存档 - 您可以在 sourceforge 来自 Dennis Wronka,采用 LGPL,因此您也可以在商业脚本中使用。
我还有一个用于 ZIP 的简单而纯的 PHP 类:
There is a very simple way to create Tar-archives directly within PHP - you can find a CLASS at sourceforge from Dennis Wronka under LGPL so you can use also in commercial scripts.
I also have a simple and pure PHP class for ZIP:
您还可以使用 PHP 压缩流包装器来压缩和解压缩文件一行:
You can also use PHP compression stream wrappers to compress and uncompress files in one line: