1

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 Answers 6

7

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.

Sign up to request clarification or add additional context in comments.

Comments

6

Sounds like you're after shell_exec().

Comments

5

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

Comments

4

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

Comments

2

You can also use system()

Comments

1

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

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

1 Comment

Which is identical to shell_exec()

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.