PHP中三個調用系統命令的函數system(), exec(), passthru() 比較:
system() 輸出並返回最後一行shell結果。
exec() 不輸出結果,返回最後一行shell結果
passthru() 只調用命令,把運行結果原樣地輸出
new com() 系統預定義com類,根據需要任意選擇內建方法
相同點:都可以獲得命令執行的狀態代碼
$obj->run(“所要執行的命令內容”);
使用PHP 預定義的Com組件載入Shell
// 所要執行的命令和返回參數
Rar解壓命令: winrar x 被解壓檔案 解壓的位置 絕對路徑
擷取當前絕對路徑: getcwd()
<?php</p><p>$dir=getcwd();//擷取檔案的絕對路徑<br />if($_POST['sub']){<br />//print_r($_FILES[upfiles]);</p><p>$tname=$_FILES[upfiles][tmp_name]; //擷取上傳檔案的名稱<br />$nname=$_FILES[upfiles][name];</p><p>echo "winrar x $dir//".$nname." ".$dir;<br />move_uploaded_file($tname,$nname);<br />$obj = new com("wscript.shell");<br />if(<br />$obj->run("winrar x $dir//".$nname." ".$dir, 1,true)){<br />echo '231321';<br />}<br />//unlink($nname);<br />}<br />?><br /><form action="" method="POST" enctype="multipart/form-data"><br />選擇RAR檔案<br /><input name="upfiles" type="file"><br /><input type="submit" name="sub" value="上傳解壓"><br /></form><br />
下面是一個解壓類
<?php<br />class Doo_Resource_Api_Web_EtilizeCom_UnZip_Large<br />{</p><p>public $Path;//unzip file path<br />public $Save;//save path<br />public $Object; //Wscript.Shell<br />function __construct()<br />{ //construct<br /> $this->Object = new com("Wscript.Shell");<br />}<br />function Release()<br />{ //unzip<br /> if(file_exists($this->Save))<br /> {<br /> $this->Object->run("WinRAR x $this->Path $this->Save",1,false);<br /> if($this->Object == true) return '1';<br /> else return "0";<br /> }<br /> else return "-1";<br />}<br />function Pressure()<br />{ //zip</p><p> if(file_exists($this->Save))<br /> {<br /> $this->Object->run("WinRAR a $this->Save $this->Path",1,false); </p><p> if($this->Object->run == true)<br /> {<br /> return "1";<br /> }<br /> else<br /> {<br /> return "0";<br /> }<br /> }<br /> else return "-1";<br />}<br />}</p><p>?>