Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

linux

php

debian

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?

like image 947
DonJuma Avatar asked Oct 11 '12 00:10

DonJuma


2 Answers

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.

like image 72
xbonez Avatar answered Oct 13 '22 01:10

xbonez


You can do what you want with the following code :

system(command);

See http://php.net/system

like image 25
Gilles Quenot Avatar answered Oct 13 '22 00:10

Gilles Quenot