在 php 中使用 Ubuntu 命令

发布于 2024-08-15 14:24:49 字数 115 浏览 3 评论 0原文

是否可以在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

软的没边 2024-08-22 14:24:49

您可以使用许多命令,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 use escapeshellarg() or escapeshellcmd(). In fact, just read this whole section of the PHP Manual first.

记忆里有你的影子 2024-08-22 14:24:49

听起来你正在寻找shell_exec()

Sounds like you're after shell_exec().

嘦怹 2024-08-22 14:24:49

更好的方法是使用 PHP 中的 ZipArchive 类。

The better way to do this is by using the ZipArchive class in PHP.

不如归去 2024-08-22 14:24:49

exec 对于这种情况很有用,但要小心,不要让用户运行这些命令。

http://php.net/manual/en/function.exec.php

<?php
echo exec('whoami');
?>

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

<?php
echo exec('whoami');
?>
爱冒险 2024-08-22 14:24:49

您还可以使用 system()

You can also use system()

不美如何 2024-08-22 14:24:49

一种更简单的方法是将命令放在``(不是''或“”)之间,是shift+tilda(~),例如您可以使用:

echo "<pre>".`ls -alh`;

An easier way is to put your command between `` (not ' ' or " " ), is shift+tilda(~) for example you can use :

echo "<pre>".`ls -alh`;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文