ArK
ArK

Reputation: 21068

using Ubuntu commands in php

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?

Upvotes: 1

Views: 9353

Answers (6)

amir beygi
amir beygi

Reputation: 1272

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

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

Upvotes: 1

Dereleased
Dereleased

Reputation: 10087

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.

Upvotes: 7

Htbaa
Htbaa

Reputation: 2309

You can also use system()

Upvotes: 2

Alan Haggai Alavi
Alan Haggai Alavi

Reputation: 74232

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

Upvotes: 5

YOU
YOU

Reputation: 123831

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');
?>

Upvotes: 4

ZoogieZork
ZoogieZork

Reputation: 11279

Sounds like you're after shell_exec().

Upvotes: 6

Related Questions