简体   繁体   中英

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?

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.

听起来好像您在追求shell_exec()

更好的方法是使用PHP中的ZipArchive类。

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

您也可以使用system()

一种更简单的方法是将命令放在`` (not ' ' or " " ),例如shift + tilda(〜),您可以使用:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM