欢迎来到代码驿站!

PHP代码

当前位置:首页 > 软件编程 > PHP代码

服务器端解压缩zip的脚本

时间:2021-04-27 09:09:58|栏目:PHP代码|点击:

复制代码 代码如下:
<!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=gb2312" />  
<title>文件解压缩管理</title>  
</head>  
<body>  
<?php  
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead  
// of $_FILES.  
if (isset($_POST["Submit"])) {  
   echo "FileName:     " . $_POST['unpackfile'] . "<br />\n";  
   echo "UnpackPath:   " . $_POST['unpackpath'] . "<br />\n";  
   $zip = zip_open($_POST['unpackfile']);  
   if ($zip) {  
      while ($zip_entry = zip_read($zip)) {  
         echo "Name:               " . zip_entry_name($zip_entry) . "<br />\n";  
         echo "Actual Filesize:    " . zip_entry_filesize($zip_entry) . "<br />\n";  
         echo "Compressed Size:    " . zip_entry_compressedsize($zip_entry) . "<br />\n";  
         echo "Compression Method: " . zip_entry_compressionmethod($zip_entry) . "<br />\n";  

         if (zip_entry_open($zip, $zip_entry, "r")) {  
            $buf = zip_entry_read($zip_entry, zip_entry_filesize($zip_entry));   // File content  
            echo "step 1 successful!<br />\n";  
            if(zip_entry_filesize($zip_entry)!=0) {  
               $fp = fopen($_POST['unpackpath']."/".zip_entry_name($zip_entry), 'wb');  
               fwrite($fp, $buf);  
               fclose($fp);  
               zip_entry_close($zip_entry);  
               echo "unpack successful!<br />\n";  
            } else {  
               mkdir($_POST['unpackpath']."/".zip_entry_name($zip_entry), 0777);  
               echo "mkdir successful!<br />\n";  
            }  
         }  
         echo "<br><br>\n\n";  
      }  
      zip_close($zip);  
   }  
?>  
</body>  
</html>  
<?php  
exit();  
}  
?>  
<form id="form1" name="form1" enctype="multipart/form-data" method="post" action="<?=$_SERVER['PHP_SELF']?>">  
  待解压文件<input type="text" name="unpackfile" />  
  解压缩路径<input type="text" name="unpackpath" />  
  <input type="submit" name="Submit" value="解压" />  
</form>  
</body>  
</html> 

上一篇:PHP+MySQL统计该库中每个表的记录数并按递减顺序排列的方法

栏    目:PHP代码

下一篇:PHP使用Alexa API获取网站的Alexa排名例子

本文标题:服务器端解压缩zip的脚本

本文地址:http://www.codeinn.net/misctech/109961.html

推荐教程

广告投放 | 联系我们 | 版权申明

重要申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:914707363 | 邮箱:codeinn#126.com(#换成@)

Copyright © 2020 代码驿站 版权所有