返回列表 发帖

很好用的PHP在线打包工具 打包源码的利器

  1. <?php

  2. //验证密码,默认 jb51.net

  3. //在URL后参加 ?pwd=密码 查看生成密码

  4. $password = 'd328ab8f8bcf16888c9a12e480a414d4';

  5. ?>

  6. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">



  7. <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="zh-CN">

  8. <head>

  9. <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />

  10. <title>PHP在线压缩程序</title>

  11. <!-- css copied from wordpress -->

  12. <style type="text/css">

  13. <!--



  14. html{background:#f9f9f9;}body{

  15. color: #333;

  16. font-family: "微软雅黑", "宋体", "黑体";

  17. margin: 2em auto;

  18. width: 700px;

  19. padding: 1em 2em;

  20. -moz-border-radius: 11px;

  21. -khtml-border-radius: 11px;

  22. -webkit-border-radius: 11px;

  23. border-radius: 11px;

  24. border: 1px solid #dfdfdf;

  25. }a{color:#2583ad;text-decoration:none;}a:hover{color:#d54e21;}h1{

  26. border-bottom: 1px solid #dadada;

  27. clear: both;

  28. color: #666;

  29. margin: 5px 0 0 -4px;

  30. padding: 0;

  31. padding-bottom: 7px;

  32. font-family: "微软雅黑", "宋体", "黑体";

  33. font-size: 24px;

  34. text-align: center;

  35. }h2{font-size:16px;}p,li,dd,dt{padding-bottom:2px;font-size:12px;line-height:18px;}code,.code{font-size:13px;}ul,ol,dl{padding:5px 5px 5px 22px;}a img{border:0;}abbr{border:0;font-variant:normal;}#logo{margin:6px 0 14px 0;border-bottom:none;text-align:center;}.step{margin:20px 0 15px;}.step,th{text-align:left;padding:0;}.submit input,.button,.button-secondary{font-family:sans-serif;text-decoration:none;font-size:14px!important;line-height:16px;padding:6px 12px;cursor:pointer;border:1px solid #bbb;color:#464646;-moz-border-radius:15px;-khtml-border-radius:15px;-webkit-border-radius:15px;border-radius:15px;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;-khtml-box-sizing:content-box;box-sizing:content-box;}.button:hover,.button-secondary:hover,.submit input:hover{color:#000;border-color:#666;}textarea{border:1px solid #bbb;-moz-border-radius:3px;-khtml-border-radius:3px;-webkit-border-radius:3px;border-radius:3px;}.form-table{border-collapse:collapse;margin-top:1em;width:100%;}.form-table td{margin-bottom:9px;padding:10px;border-bottom:8px solid #fff;font-size:12px;}.form-table th{font-size:13px;text-align:left;padding:16px 10px 10px 10px;border-bottom:8px solid #fff;width:130px;vertical-align:top;}.form-table tr{background:#f3f3f3;}.form-table code{line-height:18px;font-size:18px;}.form-table p{margin:4px 0 0 0;font-size:11px;}.form-table input{line-height:20px;font-size:15px;padding:2px;}.form-table th p{font-weight:normal;}#error-page{margin-top:50px;}#error-page p{font-size:12px;line-height:18px;margin:25px 0 20px;}#error-page code,.code{font-family:Consolas,Monaco,monospace;}#pass-strength-result{background-color:#eee;border-color:#ddd!important;border-style:solid;border-width:1px;margin:5px 5px 5px 1px;padding:5px;text-align:center;width:200px;display:none;}#pass-strength-result.bad{background-color:#ffb78c;border-color:#ff853c!important;}#pass-strength-result.good{background-color:#ffec8b;border-color:#fc0!important;}#pass-strength-result.short{background-color:#ffa0a0;border-color:#f04040!important;}#pass-strength-result.strong{background-color:#c3ff88;border-color:#8dff1c!important;}.message{

  36. border: 1px solid #e6db55;

  37. padding: .3em .6em;

  38. margin: 5px 0 15px;

  39. background-color: #FFFFCC;

  40. }

  41. .mydirname {color:#F00;}

  42. .myfilename {color:#649ABE;}

  43. .currentdir {font-size:14px;font-family: Georgia, Consolas;font-weight:bold;}

  44. #footer {text-align:center;margin-top:20px;}

  45. .fx{

  46. width: 50px;

  47. height: 25px;

  48. background-color: #FFFFCC;

  49. border: 1px dashed #666;

  50. }

  51. .ys{

  52. height: 25px;

  53. width: 200px;

  54. background-color: #FFFFCC;

  55. border: 1px dashed #666;

  56. }

  57. .ml{

  58. width: 230px;

  59. height: 25px;

  60. }

  61. .mc{

  62. width: 230px;

  63. height: 25px;

  64. }

  65. .button1 {font-family:sans-serif;text-decoration:none;font-size:14px!important;line-height:16px;padding:6px 12px;cursor:pointer;border:1px solid #bbb;color:#464646;-moz-border-radius:15px;-khtml-border-radius:15px;-webkit-border-radius:15px;border-radius:15px;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;-khtml-box-sizing:content-box;box-sizing:content-box;}

  66. .button-secondary1 {font-family:sans-serif;text-decoration:none;font-size:14px!important;line-height:16px;padding:6px 12px;cursor:pointer;border:1px solid #bbb;color:#464646;-moz-border-radius:15px;-khtml-border-radius:15px;-webkit-border-radius:15px;border-radius:15px;-moz-box-sizing:content-box;-webkit-box-sizing:content-box;-khtml-box-sizing:content-box;box-sizing:content-box;}

  67. .mm{

  68. width: 230px;

  69. height: 25px;

  70. }

  71. .jr{

  72. height: 25px;

  73. width: 100px;

  74. background-color: #FFC;

  75. border: 1px dashed #666;

  76. }

  77. -->

  78. </style>

  79. </head>



  80. <body>

  81.   <form name="myform" id="myform" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">

  82. <h1 style="color:#2583ad;">在线压缩ZIP文件程序</h1><br>



  83. <div class="message">

  84.       <p>使用方法:选定要压缩的文件或目录(包含子目录),即可开始压缩。压缩的结果保留原来的目录结构。<br />

  85.       <?php if(isset($_REQUEST['pwd']) && md5($_REQUEST['pwd']) == $password)

  86.   echo '当前目录:<span class="currentdir">'. dirname(__FILE__) . '</span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="'.

  87.   $_SERVER['PHP_SELF']. '">退出</a>';

  88.   else

  89. if(isset($_GET['pwd']) )

  90. echo '密码值:<span class="currentdir">'. md5($_GET['pwd']) . '</span>';

  91. else

  92. echo 'Tips:在URL后参加<span class="currentdir">?pwd=密码</span> 查看生成密码.';

  93.     ?>

  94.   </p>

  95. </div>

  96. <?

  97. if(!isset($_REQUEST["myaction"])):

  98. ?>

  99. <table width="100%" border="0" cellspacing="0" cellpadding="0">

  100. <tr>

  101.       <td width="11%">验证密码: </td>

  102.       <td width="89%"><input class="mm" name="pwd" type="password" id="password" onkeydown="if(event.ctrlKey&&event.keyCode==13){document.getElementById('login').click();return false};">

  103.       <input type="submit" name="login" id="login" class="jr" value=" 进 入 " /></td>

  104.     </tr>

  105.     <tr>

  106.       <td><input name="myaction" type="hidden" id="myaction" value="dolist"></td>

  107.       <td>&nbsp;</td>

  108.     </tr>

  109.   </table>

  110.   <script type="text/javascript">

  111.   document.getElementById('password').focus();

  112.   </script>

  113. <?



  114. elseif($_REQUEST["myaction"]=="dolist"):



  115. if(!isset($_REQUEST['pwd']) || empty($_REQUEST['pwd']) )

  116. die('请输入密码! <a href="'. $_SERVER['PHP_SELF']. '">Again</a>');

  117. if(md5($_REQUEST['pwd']) != $password)

  118.     die('输入的密码不正确!<a href="'. $_SERVER['PHP_SELF']. '">Again</a>');

  119. echo '选择要排除的目录(相对路径,以英文半角逗号分隔):<br />';

  120. echo '<input type="text" id="toexlude" name="toexlude" size="100" /><br />';

  121. echo "选择要压缩的文件或目录:<br/>";

  122.   $fdir = opendir('./');

  123. while($file=readdir($fdir)){

  124. if($file=='.'|| $file=='..' ) continue;

  125. echo "<input name='dfile[]' type='checkbox' value='$file' ".($file==basename(__FILE__)?"":"checked")."> ";

  126. if(is_file($file)){

  127. echo "<span class='myfilename'>文件: $file</span><br>";

  128. }else{

  129. echo "<span class='mydirname'>目录: $file</span><br>";

  130. }

  131. }

  132. ?>

  133. <br>

  134. 保存目录:

  135. <input name="todir" type="text" class="ml" id="todir" value=""> (留空为本目录,必须有写入权限)

  136. <!--

  137. value="_zipfiles<?php echo substr(md5(time()),0,8);?>_"

  138. -->

  139. <br>

  140. <br>

  141. 文件名称:

  142. <input name="zipname" type="text" class="mc" id="zipname" value="zip">

  143. (.zip)

  144. <!--value="backup_<?php echo substr(md5(__FILE__),0,8);?>.zip"-->

  145. <br>

  146. <br>

  147. <input name="pwd" type="hidden" id="password" value="<?php echo $_POST['pwd'];?>">

  148. <input name="myaction" type="hidden" id="myaction" value="dozip">

  149. <input class="fx" type='button' value='反选' onclick='selrev();'>

  150. <input class="ys" type="submit" name="Submit" value=" 开 始 压 缩 ">

  151. <script language='javascript'>

  152. function selrev() {

  153. with(document.getElementById('myform')){

  154. for(i=0;i<elements.length;i++) {

  155. thiselm = elements[i];

  156. if(thiselm.name.match(/dfile\[]/))thiselm.checked = !thiselm.checked;

  157. }

  158. }

  159. }

  160. </script>

  161. <?



  162. elseif($_REQUEST["myaction"]=="dozip"):



  163.   set_time_limit(0);



  164.   class PHPzip{



  165. var $file_count = 0 ;

  166. var $datastr_len   = 0;

  167. var $dirstr_len = 0;

  168. var $filedata = ''; //该变量只被类外部程序访问

  169. var $gzfilename;

  170. var $fp;

  171. var $dirstr='';

  172. /*

  173. 返回文件的修改时间格式.

  174. 只为本类内部函数调用.

  175. */

  176.     function unix2DosTime($unixtime = 0) {

  177.         $timearray = ($unixtime == 0) ? getdate() : getdate($unixtime);



  178.         if ($timearray['year'] < 1980) {

  179.         $timearray['year']    = 1980;

  180.         $timearray['mon']     = 1;

  181.         $timearray['mday']    = 1;

  182.         $timearray['hours']   = 0;

  183.         $timearray['minutes'] = 0;

  184.         $timearray['seconds'] = 0;

  185.         }



  186.         return (($timearray['year'] - 1980) << 25) | ($timearray['mon'] << 21) | ($timearray['mday'] << 16) |

  187.                ($timearray['hours'] << 11) | ($timearray['minutes'] << 5) | ($timearray['seconds'] >> 1);

  188.     }



  189. /*

  190. 初始化文件,建立文件目录,

  191. 并返回文件的写入权限.

  192. */

  193. function startfile($path = 'myzip.zip'){

  194. $this->gzfilename=$path;

  195. $mypathdir=array();

  196. do{

  197. $mypathdir[] = $path = dirname($path);

  198. }while($path != '.');

  199. @end($mypathdir);

  200. do{

  201. $path = @current($mypathdir);

  202. @mkdir($path);

  203. }while(@prev($mypathdir));



  204. if($this->fp=@fopen($this->gzfilename,"w")){

  205. return true;

  206. }

  207. return false;

  208. }



  209. /*

  210. 添加一个文件到 zip 压缩包中.

  211. */

  212.     function addfile($data, $name){

  213.         $name     = str_replace('\\', '/', $name);

  214. if(strrchr($name,'/')=='/') return $this->adddir($name);

  215.         $dtime    = dechex($this->unix2DosTime());

  216.         $hexdtime = '\x' . $dtime[6] . $dtime[7]

  217.                   . '\x' . $dtime[4] . $dtime[5]

  218.                   . '\x' . $dtime[2] . $dtime[3]

  219.                   . '\x' . $dtime[0] . $dtime[1];

  220.         eval('$hexdtime = "' . $hexdtime . '";');



  221.         $unc_len = strlen($data);

  222.         $crc     = crc32($data);

  223.         $zdata   = gzcompress($data);

  224.         $c_len   = strlen($zdata);

  225.         $zdata   = substr(substr($zdata, 0, strlen($zdata) - 4), 2);

  226. //新添文件内容格式化:

  227.         $datastr  = "\x50\x4b\x03\x04";

  228.         $datastr .= "\x14\x00";            // ver needed to extract

  229.         $datastr .= "\x00\x00";            // gen purpose bit flag

  230.         $datastr .= "\x08\x00";            // compression method

  231.         $datastr .= $hexdtime;             // last mod time and date

  232.         $datastr .= pack('V', $crc);             // crc32

  233.         $datastr .= pack('V', $c_len);           // compressed filesize

  234.         $datastr .= pack('V', $unc_len);         // uncompressed filesize

  235.         $datastr .= pack('v', strlen($name));    // length of filename

  236.         $datastr .= pack('v', 0);                // extra field length

  237.         $datastr .= $name;

  238.         $datastr .= $zdata;

  239.         $datastr .= pack('V', $crc);                 // crc32

  240.         $datastr .= pack('V', $c_len);               // compressed filesize

  241.         $datastr .= pack('V', $unc_len);             // uncompressed filesize



  242. fwrite($this->fp,$datastr);//写入新的文件内容

  243. $my_datastr_len = strlen($datastr);

  244. unset($datastr);

  245. //新添文件目录信息

  246.         $dirstr  = "\x50\x4b\x01\x02";

  247.         $dirstr .= "\x00\x00";                // version made by

  248.         $dirstr .= "\x14\x00";                // version needed to extract

  249.         $dirstr .= "\x00\x00";                // gen purpose bit flag

  250.         $dirstr .= "\x08\x00";                // compression method

  251.         $dirstr .= $hexdtime;                 // last mod time & date

  252.         $dirstr .= pack('V', $crc);           // crc32

  253.         $dirstr .= pack('V', $c_len);         // compressed filesize

  254.         $dirstr .= pack('V', $unc_len);       // uncompressed filesize

  255.         $dirstr .= pack('v', strlen($name) ); // length of filename

  256.         $dirstr .= pack('v', 0 );             // extra field length

  257.         $dirstr .= pack('v', 0 );             // file comment length

  258.         $dirstr .= pack('v', 0 );             // disk number start

  259.         $dirstr .= pack('v', 0 );             // internal file attributes

  260.         $dirstr .= pack('V', 32 );            // external file attributes - 'archive' bit set

  261.         $dirstr .= pack('V',$this->datastr_len ); // relative offset of local header

  262.         $dirstr .= $name;

  263. $this->dirstr .= $dirstr;//目录信息

  264. $this -> file_count ++;

  265. $this -> dirstr_len += strlen($dirstr);

  266. $this -> datastr_len += $my_datastr_len;

  267.     }



  268. function adddir($name){

  269. $name = str_replace("\\", "/", $name);

  270. $datastr = "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00";

  271. $datastr .= pack("V",0).pack("V",0).pack("V",0).pack("v", strlen($name) );

  272. $datastr .= pack("v", 0 ).$name.pack("V", 0).pack("V", 0).pack("V", 0);



  273. fwrite($this->fp,$datastr);//写入新的文件内容

  274. $my_datastr_len = strlen($datastr);

  275. unset($datastr);

  276. $dirstr = "\x50\x4b\x01\x02\x00\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00";

  277. $dirstr .= pack("V",0).pack("V",0).pack("V",0).pack("v", strlen($name) );

  278. $dirstr .= pack("v", 0 ).pack("v", 0 ).pack("v", 0 ).pack("v", 0 );

  279. $dirstr .= pack("V", 16 ).pack("V",$this->datastr_len).$name;

  280. $this->dirstr .= $dirstr;//目录信息



  281. $this -> file_count ++;

  282. $this -> dirstr_len += strlen($dirstr);

  283. $this -> datastr_len += $my_datastr_len;

  284. }



  285. function createfile(){

  286. //压缩包结束信息,包括文件总数,目录信息读取指针位置等信息

  287. $endstr = "\x50\x4b\x05\x06\x00\x00\x00\x00" .

  288. pack('v', $this -> file_count) .

  289. pack('v', $this -> file_count) .

  290. pack('V', $this -> dirstr_len) .

  291. pack('V', $this -> datastr_len) .

  292. "\x00\x00";



  293. fwrite($this->fp,$this->dirstr.$endstr);

  294. fclose($this->fp);

  295. }

  296.   }



  297. if(!trim($_REQUEST['zipname']))

  298. $_REQUEST['zipname'] = 'backup_'.substr(md5(__FILE__),0,8). '.zip';

  299. else

  300. $_REQUEST['zipname'] = trim($_REQUEST['zipname']);

  301. if(!strrchr(strtolower($_REQUEST['zipname']),'.')=='.zip')

  302. $_REQUEST['zipname'] .= ".zip";

  303. $_REQUEST['todir'] = str_replace('\\','/',trim($_REQUEST['todir']));

  304. if(!strrchr(strtolower($_REQUEST['todir']),'/')=='/')

  305. $_REQUEST['todir'] .= "/";

  306. if($_REQUEST['todir']=="/")

  307. $_REQUEST['todir'] = "./";

  308. function listfiles($dir="."){

  309. global $faisunZIP;

  310. $sub_file_num = 0;



  311. if(is_file($dir)){

  312.   if(realpath($faisunZIP->gzfilename)!=realpath($dir)){

  313. $faisunZIP -> addfile(implode('',file($dir)),$dir);

  314. return 1;

  315.   }

  316. return 0;

  317. }

  318. $handle=opendir($dir);

  319. //添加排除

  320. $to_exlude = !empty($_POST['toexlude']) ? $_POST['toexlude'] :'';

  321. $exlude = empty($to_exlude) ? array() : explode(',',$to_exlude);

  322. while ($file = readdir($handle)) {

  323.    if($file=="."||$file==".." || $file == 'wp-content' )continue;

  324.    if(is_dir("$dir/$file") && !in_array("$dir/$file",$exlude) )

  325.    {

  326. $sub_file_num += listfiles("$dir/$file");

  327.    }

  328.    else {

  329.       if(realpath($faisunZIP ->gzfilename)!=realpath("$dir/$file")){

  330.      $faisunZIP -> addfile(implode('',file("$dir/$file")),"$dir/$file");

  331. $sub_file_num ++;

  332. }

  333.    }

  334. }

  335. closedir($handle);

  336. if(!$sub_file_num) $faisunZIP -> addfile("","$dir/");

  337. return $sub_file_num;

  338. }



  339. function num_bitunit($num){

  340.   $bitunit=array(' B',' KB',' MB',' GB');

  341.   for($key=0;$key<count($bitunit);$key++){

  342. if($num>=pow(2,10*$key)-1){ //1023B 会显示为 1KB

  343.   $num_bitunit_str=(ceil($num/pow(2,10*$key)*100)/100)." $bitunit[$key]";

  344. }

  345.   }

  346.   return $num_bitunit_str;

  347. }

  348. if(is_array($_REQUEST['dfile'])){

  349. $faisunZIP = new PHPzip;

  350. if($faisunZIP -> startfile($_REQUEST['todir'].$_REQUEST['zipname'])){

  351. echo "正在添加压缩文件...<br><br>";

  352. $filenum = 0;

  353. foreach($_REQUEST['dfile'] as $file){

  354. if(is_file($file)){

  355. echo "<span class='myfilename'>文件: $file </span><br>";

  356. }else{

  357. echo "<span class='mydirname'>目录: $file </span><br>";

  358. }

  359. $filenum += listfiles($file);

  360. }

  361. $faisunZIP -> createfile();

  362. echo "<br>压缩完成,共添加 $filenum 个文件.<br /><a href='" .$_REQUEST['todir'].$_REQUEST['zipname']. "'>". $_REQUEST['todir'].$_REQUEST['zipname']." (".num_bitunit(filesize("$_REQUEST[todir]$_REQUEST[zipname]")).")</a>";

  363. }else{

  364. echo $_REQUEST['todir'].$_REQUEST['zipname'].'不能写入,请检查路径或权限是否正确.<br>';

  365. }

  366. }else{

  367. echo "没有选择的文件或目录.<br>";

  368. }



  369. endif;



  370. ?>

  371.   </form>

  372.   <div id="footer">

  373.   <p><a href="http://www.iuui.cc/">〈 拨清波 〉</a><a href="javascript:;" onclick="scrollTo(0,0);" title="返回顶部">TOP</a></p>

  374.   </div>

  375. </body>

  376. </html>
复制代码
欢迎光临:逐梦论坛

返回列表

Powered by Discuz! 7.2   论坛QQ群:逐梦论坛群

© 2001-2021 Comsenz Inc. 鲁公网安备 37120302000001号