在Linux中,可以通過在PHP腳本中使用shell_exec()或exec()函數來執行Linux命令并設置參數
shell_exec()函數:<?php
$command = "ls -l"; // 這里可以替換為你想要的命令
$arguments = "-a -h"; // 這里可以替換為你想要的參數
$output = shell_exec("$command $arguments"); // 執行命令并獲取輸出結果
echo "<pre>$output</pre>"; // 輸出結果
?>
exec()函數:<?php
$command = "ls"; // 這里可以替換為你想要的命令
$arguments = "-la"; // 這里可以替換為你想要的參數
exec("$command $arguments", $output, $return_var); // 執行命令并獲取輸出結果
if ($return_var === 0) {
echo "<pre>";
foreach ($output as $line) {
echo $line . PHP_EOL;
}
echo "</pre>"; // 輸出結果
} else {
echo "Error: Command execution failed.";
}
?>
在這兩個示例中,我們使用了ls命令和參數-l和-a(-la)來列出當前目錄下的所有文件和文件夾(包括隱藏文件)。你可以根據需要替換為其他命令和參數。