How can I run a linux command from a PHP script [duplicate]

牧云@^-^@ 提交于 2019-12-18 04:52:32

问题


Possible Duplicate:
php shell_exec() vs exec()

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?


回答1:


Use exec to run any command. Be careful not to exec any user input though, as it can severely compromise your server.

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.




回答2:


You can do what you want with the following code :

system(command);

See http://php.net/system




回答3:


You can execute linux commands within a php script - all you have to do is put the command line in brackits (`).

And also concentrate on exec() , this and shell_exec() ..




回答4:


you can use

exec
shell_exec

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



来源:https://stackoverflow.com/questions/12830520/how-can-i-run-a-linux-command-from-a-php-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!