php在windows平台执行shell解压文件

来源:互联网 发布:淘宝开店经验交流 编辑:程序博客网 时间:2024/06/06 12:20
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>

<form action="" method="post" enctype="multipart/form-data">
选择文件:<input name="myrar" type="file" /><br />
<input name="sub" value="提交解压文件" type="submit"/>
</form>
<?php
if(isset($_POST['sub']))
{
 $datetime=date("Ymdhis");
 $arr=explode(".",$_FILES["myrar"]["name"]);
 $exce=$arr[1];//获取扩展名
 $allowarr=array("rar");//允许上传的扩展名
 if(!in_array($exce,$allowarr)){echo "文件类型不允许";exit();}
 $newname=$datetime.".".$exce;//重命名文件
 $path="rar/" .$newname;
 $a=@move_uploaded_file($_FILES['myrar']['tmp_name'],$path);
 //具体参见php手册,这个是移动文件到$path文件夹下
 if($a){
 //进行解压操作
 echo "上传成功,执行解压。。。";
$obj=new com("wscript.shell");//com组建   加载wscript.shell用来执行dos命令组件
 $dir=getcwd();//获取当前目录路径
 $shell="winrar x $dir\\"."rar"."\\".$newname." $dir";
 $obj->run($shell,1,true);//执行脚本  
 echo "解压成功。。。删除原来压缩包。。。";
 //unlink($path);//删除上传的压缩包
 }
}
 
?>

</body>
</html>
原创粉丝点击