views:

172

answers:

6

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?

+6  A: 

Sounds like you're after shell_exec().

ZoogieZork
+4  A: 

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');
?>
S.Mark
+5  A: 

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

Alan Haggai Alavi
+2  A: 

You can also use system()

Htbaa
+7  A: 

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.

Dereleased
+1 for security considerations
Boldewyn
+1  A: 

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

echo "<pre>".`ls -alh`;
amir beygi
Which is identical to shell_exec()
Htbaa