在 php 中使用 Ubuntu 命令
是否可以在 php 程序中使用 ubuntu 终端命令。例如,我需要创建一个文件夹并使用 php 压缩(.zip)它程序。如何编写这个需求的代码?
Is it possible to use ubuntu terminal commands in php program.for example i need to create a folder and compress (.zip) it using php program. How to code this need?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可以使用许多命令,
exec()
、shell_exec()
、passthru()
、system()< /code> 仅举几例。请记住,如果您打算让它在任何地方,甚至远程靠近用户输入(即使是上传的文件),您应该使用
escapeshellarg()
或escapeshellcmd()
。事实上,只需先阅读PHP 手册的整个部分即可。There are a host of commands you can use,
exec()
,shell_exec()
,passthru()
,system()
just to name a few. Just remember, if you intend to let this anywhere even remotely near user input (Even for uploaded files) you should useescapeshellarg()
orescapeshellcmd()
. In fact, just read this whole section of the PHP Manual first.听起来你正在寻找shell_exec()。
Sounds like you're after shell_exec().
更好的方法是使用 PHP 中的 ZipArchive 类。
The better way to do this is by using the ZipArchive class in PHP.
exec 对于这种情况很有用,但要小心,不要让用户运行这些命令。
http://php.net/manual/en/function.exec.php
exec will be useful for that case, but be careful, don't let user to run those commands.
http://php.net/manual/en/function.exec.php
您还可以使用 system()
You can also use system()
一种更简单的方法是将命令放在``
(不是''或“”)之间,
是shift+tilda(~),例如您可以使用:An easier way is to put your command between ``
(not ' ' or " " ),
is shift+tilda(~) for example you can use :