string exec ( string $command [, array &$output [, int &$return_var ]] )
void passthru ( string $command [, int &$return_var ] )
注意的是:這三個函數(shù)在默認的情況下,都是被禁止了的,如果要使用這幾個函數(shù),就要先修改php的配置文件php.ini,查找關(guān)鍵字disable_functions,將這一項中的這幾個函數(shù)名刪除掉,然后注意重啟apache。
首先看一下system()和passthru()兩個功能類似,可以互換:
<?php
$shell = "ls -la";
echo "<pre>";
system($shell, $status);
echo "</pre>";
//注意shell命令的執(zhí)行結(jié)果和執(zhí)行返回的狀態(tài)值的對應(yīng)關(guān)系
$shell = "<font color='red'>$shell</font>";
if( $status ){
echo "shell命令{$shell}執(zhí)行失敗";
} else {
echo "shell命令{$shell}成功執(zhí)行";
}
?>
執(zhí)行結(jié)果如下:
<?php
$shell = "ls -la";
exec($shell, $result, $status);
$shell = "<font color='red'>$shell</font>";
echo "<pre>";
if( $status ){
echo "shell命令{$shell}執(zhí)行失敗";
} else {
echo "shell命令{$shell}成功執(zhí)行, 結(jié)果如下<hr>";
print_r( $result );
}
echo "</pre>";
?>
運行結(jié)果如下:
更多關(guān)于云服務(wù)器,域名注冊,虛擬主機的問題,請訪問西部數(shù)碼官網(wǎng):m.ps-sw.cn