PHP中三个调用系统命令的函数system(), exec(), passthru() 比较:
system() 输出并返回最后一行shell结果。
exec() 不输出结果,返回最后一行shell结果
passthru() 只调用命令,把运行结果原样地输出
new com() 系统预定义com类,根据需要任意选择内置方法
相同点:都可以获得命令执行的状态码
$obj->run(“所要执行的命令内容”);
使用PHP 预定义的Com组件加载Shell
// 所要执行的命令和返回参数
Rar解压命令: winrar x 被解压文件 解压的位置 绝对路径
获取当前绝对路径: getcwd()
$dir=getcwd();//获取文件的绝对路径
if($_POST['sub']){
//print_r($_FILES[upfiles]);
$tname=$_FILES[upfiles][tmp_name]; //获取上传文件的名称
$nname=$_FILES[upfiles][name];
echo "winrar x $dir//".$nname." ".$dir;
move_uploaded_file($tname,$nname);
$obj = new com("wscript.shell");
if(
$obj->run("winrar x $dir//".$nname." ".$dir, 1,true)){
echo '231321';
}
//unlink($nname);
}
?>
选择RAR文件
下面是一个解压类
class Doo_Resource_Api_Web_EtilizeCom_UnZip_Large
{
public $Path;//unzip file path
public $Save;//save path
public $Object; //Wscript.Shell
function __construct()
{ //construct
$this->Object = new com("Wscript.Shell");
}
function Release()
{ //unzip
if(file_exists($this->Save))
{
$this->Object->run("WinRAR x $this->Path $this->Save",1,false);
if($this->Object == true) return '1';
else return "0";
}
else return "-1";
}
function Pressure()
{ //zip
if(file_exists($this->Save))
{
$this->Object->run("WinRAR a $this->Save $this->Path",1,false);
if($this->Object->run == true)
{
return "1";
}
else
{
return "0";
}
}
else return "-1";
}
}
?>