如何从PHP脚本运行linux命令 [英] How can I run a linux command from a PHP script
问题描述
我从PHP脚本运行一个linux命令?我正在运行Linux Debian和PHP5。我希望能够向控制台发出一个 wget
命令。
How do I run a linux command from a PHP script? I'm running Linux Debian and PHP5. I want to be able to issue a wget
command to the console.
我正在看的一个例子这是这样的:
An example of what I'm looking for is something like this:
phpFunction ("wget http://www.example.com/image.jpg /folder");
echo "done";
我还能回显该函数的输出吗?
Also would I be able to echo the output of that function?
推荐答案
使用 exec
运行任何命令。请注意,不要执行任何用户输入,因为它可能严重损害您的服务器。
Use exec
to run any command. Be careful not to exec any user input though, as it can severely compromise your server.
另外请注意,大多数共享服务器阻止了 exec
函数,所以你将无法使用它。
Also, note that most shared servers block off the exec
function so you won't be able to use it.
最后,作为一个简写,你可以包装你要执行的命令反驳。
Finally, as a shorthand, you can wrap the command you want to exec in backticks.
这篇关于如何从PHP脚本运行linux命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!