PHP中三個(gè)調(diào)用系統(tǒng)命令的函數(shù)system(), exec(), passthru() 比較:
system() 輸出并返回最后一行shell結(jié)果。
exec() 不輸出結(jié)果,返回最后一行shell結(jié)果
passthru() 只調(diào)用命令,把運(yùn)行結(jié)果原樣地輸出
new com() 系統(tǒng)預(yù)定義com類(lèi),根據(jù)需要任意選擇內(nèi)置方法
相同點(diǎn):都可以獲得命令執(zhí)行的狀態(tài)碼
使用PHP 預(yù)定義的Com組件加載Shell
$obj=new com("wscript.shell");//加載wscript.shell用來(lái)執(zhí)行dos命令的組件 $obj->run(“所要執(zhí)行的命令內(nèi)容”);//所要執(zhí)行的命令和返回參數(shù) //Rar解壓命令: winrar x 被解壓文件 加壓的位置
補(bǔ)充知識(shí)
獲取當(dāng)前絕對(duì)路徑: getcwd() 上傳移動(dòng)文件函數(shù): move_uploaded_file()
<?php $dir=getcwd();//獲取當(dāng)前絕對(duì)路徑 if($_POST[sub]){ $tname=$_FILES[upfiles][tmp_name]; $nname=$_FILES[upfiles][name]; move_uploaded_file($tname,$nname); $obj=new com("wscript.shell");//加載wscript.shell用來(lái)執(zhí)行dos命令的組件 $obj->run("winrar x $dir\\".$nname." ".$dir , 1,true);//所要執(zhí)行的命令和返回參數(shù) unlink($nname); } ?> <form action="" method="POST" enctype="multipart/form-data"> 選擇上傳文件 <input type="file" name="upfiles"/> <input type="submit" name='sub' value='提交并解壓' > </form>
微信掃碼
關(guān)注PHP中文網(wǎng)服務(wù)號(hào)
QQ掃碼
加入技術(shù)交流群
Copyright 2014-2025 http://ipnx.cn/ All Rights Reserved | php.cn | 湘ICP備2023035733號(hào)