网站地图    收藏   

主页 > php专栏 > php综合实列 >

php 在线解压程序 - 综合实例

来源:自学PHP网    时间:2014-12-02 13:09 作者: 阅读:次

[导读] ?phpHtmlHead(选择解压文件:);if(!IsSet($HTTP_POST_VARS[#39;submit#39;])){TestWriteable();$gzip_info=;echocheckzlibsupport........

php 在线解压程序

  1. <?php 
  2. HtmlHead("选择解压文件:") ; 
  3.  
  4. if ( !IsSet($HTTP_POST_VARS['submit']) ) 
  5. { 
  6.  TestWriteable() ; 
  7.  $gzip_info = "" ; 
  8.  echo "check zlib support... " ; 
  9.  if ( !function_exists("gzopen") ) 
  10.  { 
  11.   $gzip_info = "<font color="red">注意! 您的空间没有zlib支持,因此用 
  12.   <a href="http://www.phpfensi.com/" target="_blank"><font color="blue">phpZip</font></a>  
  13.   压缩文件时,不要选择“压缩成Gzip格式”,否则将无法正确解压!</font>" ; 
  14.  } 
  15.  else 
  16.  { 
  17.   $gzip_info = "<font color="blue">恭喜! 您的空间支持zlib压缩,强烈建议用  
  18.   <a href="http://www.phpfensi.com/"><font color="red" target="_blank">phpZip</font></a>  
  19.   压缩文件时,选中“压缩成Gzip格式”,将会大大减少文件大小!</font>" ; 
  20.  } 
  21.  echo " ----------------- OK!<br> " . $gzip_info ; 
  22.   
  23.  echo "<br><br><br><br> 
  24. <form action="{$_SERVER["PHP_SELF"]}" method="post" enctype="multipart/form-data"> 
  25. <table align="center" width="450"> 
  26. <tr><td height="20" colspan="2">请先选择压缩文件的位置,然后点击“确定”按钮: <p></td></tr> 
  27. <tr> 
  28. <td><input type="radio" name="file_type" value="upload" checked onclick="this.form.upload_file.disabled=false; this.form.server_filename.disabled=true">文件从本地上传: </td>  
  29. <td> 
  30. <input name="upload_file" type="file" style="color:#0000ff"> 
  31. </td> 
  32. </tr> 
  33.  
  34. <tr><td colspan=2 height=10></td></tr> 
  35.  
  36. <tr> 
  37. <td><input type="radio" name="file_type" value="server" onclick="this.form.upload_file.disabled=true; this.form.server_filename.disabled=false">指定服务器上文件:</td> 
  38. <td><input name="server_filename" value="data.dat.gz" style="color:#0000ff" disabled >(可以用"."表示当前目录)</td> 
  39. </tr> 
  40.  
  41. <tr><td colspan="2" align=center><br><input type="submit" name="submit" value="确定"></td></tr> 
  42. </table> 
  43. </form> 
  44. " ; 
  45.  HtmlFoot() ; 
  46.  exit ; 
  47. } 
  48.  
  49. if ( $_POST['file_type'] == 'upload' ) 
  50. { 
  51.  $tmpfile = $_FILES['upload_file']['tmp_name'] ; 
  52. } 
  53. else 
  54. { 
  55.  $tmpfile = $_POST['server_filename'] ; 
  56. } 
  57.  
  58. if ( !$tmpfile ) 
  59. { 
  60.  exit("无效的文件或文件不存在,可能原因有文件大小太大,上传失败或没有指定服务器端文件等") ;  
  61. } 
  62.  
  63. $bgzExist = FALSE ; 
  64. if ( function_exists("gzopen") ) 
  65. { 
  66.  $bgzExist = TRUE ; 
  67. } 
  68.  
  69. $alldata = "" ; 
  70. $pos = 0 ; 
  71.  
  72. $gzp = $bgzExist ? @gzopen($tmpfile, "rb") : @fopen($tmpfile, "rb") ; 
  73. $szReaded = "has" ; 
  74. while ( $szReaded ) 
  75. { 
  76.  $szReaded = $bgzExist ? @gzread($gzp, 2*1024*1024) : @fread($gzp, 2*1024*1024) ; 
  77.  $alldata .= $szReaded ; 
  78. } 
  79. $bgzExist ? @gzclose($gzp) : @fclose($gzp) ; 
  80.  
  81. $nFileCount = substr($alldata, $pos, 16) ; 
  82. $pos += 16 ; 
  83.  
  84. $size = substr($alldata, $pos, 16) ; 
  85. $pos += 16 ; 
  86.  
  87. $info = substr($alldata, $pos, $size-1) ;  // strip the last ' ' 
  88. $pos += $size ; 
  89.  
  90. $info_array = explode(" ", $info) ; 
  91.  
  92. $c_file = 0 ; 
  93. $c_dir = 0 ; 
  94.  
  95. foreach ($info_array as $str_row) 
  96. { 
  97.  list($filename, $attr) = explode("|", $str_row); 
  98.  if ( substr($attr,0,6) == "[/dir]" ) 
  99.  { 
  100.   echo "End of dir $filename<br>"; 
  101.   continue; 
  102.  } 
  103.   
  104.  if ( substr($attr,0,5)=="[dir]" ) 
  105.  { 
  106.   if ( @mkdir($filename, 0777) ) 
  107.    echo "Make dir $filename<br>"; 
  108.   $c_dir++ ; 
  109.  } 
  110.  else 
  111.  { 
  112.   $fp = @fopen($filename, "wb") or exit("不能新建文件 $filename ,因为没有写权限,请修改权限"); 
  113.   @fwrite($fp, substr($alldata, $pos, $attr) ); 
  114.   $pos += $attr ; 
  115.   fclose($fp); 
  116.   echo "Create file $filename<br>"; 
  117.   $c_file++ ; 
  118.  } 
  119. } 
  120.  
  121. if ( $_POST['file_type'] == 'upload' ) 
  122. { 
  123.  if ( @unlink($tmpfile) ) echo "删除临时文件 $tmpfile...<br>" ; 
  124. } 
  125.  
  126. echo "<h1>操作完毕! 共解出文件 $c_file 个, 文件夹 $c_dir 个,谢谢使用!</h1><p>" ; 
  127. HtmlFoot() ; 
  128.  
  129.  
  130. function TestWriteable() 
  131. { 
  132.  $safemode = ' 
  133. 新建一文件,命名为 unzip2.php (或其它名字), 其内容如下: 
  134.  
  135. <?php 
  136. copy("unzip.php", "unzip_safe.php") ; 
  137. header("location:unzip_safe.php") ; 
  138. ?> 
  139.  
  140. 将这个文件上传到服务器,与unzip.php同一个目录下, 
  141. 运行 unzip2.php 这个程序。 
  142.  
  143. 如果还是不行的话,那就是空间实在不支持,没有办法,很对不住您,浪费您的时间. 
  144.  ' ; 
  145.  echo "check PHP version... " . phpversion() . " -------- OK!<br> " ; 
  146.  echo "testing Permission... " ; 
  147.  
  148.  $fp = @fopen("phpzip.test", "wb") ; 
  149.  if ( FALSE !== $fp ) 
  150.  { 
  151.   fclose($fp) ; 
  152.   @unlink("phpzip.test") ; 
  153.  } 
  154.  else 
  155.  { 
  156.   exit("当前目录没有写的权限,请将当前目录属性修改为:777 ") ; 
  157.  } 
  158.  
  159.  $dir = "phpziptest" ; 
  160.  $file = "$dir/test.txt.php" ; 
  161.  @mkdir($dir, 0777) ; 
  162.  $fp = @fopen($file, "wb") ; 
  163.  if ( FALSE === $fp ) 
  164.  { 
  165.   @rmdir($dir) ; 
  166.   exit ("没有权限在程序创建的文件夹下创建文件 ,很可能是PHP安全模式所致,解决方法如下:<p><center><textarea cols=110 rows=15>$safemode</textarea></center>") ; 
  167.  } 
  168.  @fclose($fp) ; 
  169.  @unlink($file) ; 
  170.  @rmdir($dir) ; 
  171.  echo " ----------------- OK!<br> " ; 
  172. } 
  173.  
  174. function HtmlHead($title="", $css教程_file="") 
  175. { 
  176.  echo "<html> " 
  177.   . " " 
  178.   . "<head> " 
  179.   . "<meta http-equiv="Content-Type" content="text/html; charset=gb2312"> " 
  180.   . "<title>$title</title> " 
  181.   . "<style type="text/css"> " 
  182.   . "body,pre,td {font-size:12px; background-color:#fcfcfc; font-family:Tahoma,verdana,Arial} " 
  183.   . "input,textarea{font-size:12px; background-color:#f0f0f0; font-family:Tahoma,verdana,Arial} " 
  184.   . "</style> " 
  185.   . "</head> " 
  186.   . " " 
  187.   . "<body> " ; 
  188. } 
  189.  
  190. function HtmlFoot() 
  191. { 
  192.  echo "<center><font size="5" face="楷体_GB2312" color="red">使用完请立即删除本文件,以避免被其它人发现使用!</font></center> " 
  193.   . "<br><hr color="#003388"> " 
  194.   . "<center> " 
  195.   . "<p style="font-family:verdana; font-size:12px">Contact us: " 
  196.   . "<a href="http://www.phpfensi.com/" target="_blank">http://www.phpfensi.com/</a></p> " 
  197.   . "</center> " 
  198.   . "</body> " 
  199.   . " " 
  200.   . "</html>" ; 
  201. } 
  202. ?> 

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论