php一键打包网站
1 <?php
3 //在URL后参加 ?pwd=密码 查看生成密码 4 $password = '07033fc371d9b20a90bb37f46c9dea9c'; 5 ?> 6 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 7 8 <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="zh-CN"> 9 <head> 10 <meta http-equiv="Content-Type" content="text/html; charset=gbk" /> 11 <title>ZIP压缩程序 荒野无灯修改版</title> 12 <!-- css copied from wordpress --> 13 <style type="text/css"> 14 <!-- 15 16 html{background:#f9f9f9;}body{background:#fff;color:#333;font-family:sans-serif;margin:2em auto;width:700px;padding:1em 2em;-moz-border-radius:11px;-khtml-border-radius:11px;-webkit-border-radius:11px;border-radius:11px;border:1px solid #dfdfdf;}a{color:#2583ad;text-decoration:none;}a:hover{color:#d54e21;}h1{border-bottom:1px solid #dadada;clear:both;color:#666;font:24px Georgia,"Times New Roman",Times,serif;margin:5px 0 0 -4px;padding:0;padding-bottom:7px;}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{border:1px solid #e6db55;padding:.3em .6em;margin:5px 0 15px;background-color:#ffffe0;} 17 .mydirname {color:#F00;} 18 .myfilename {color:#649ABE;} 19 .currentdir {font-size:14px;font-family: Georgia, Consolas;font-weight:bold;} 20 #footer {text-align:center;margin-top:20px;} 21 --> 22 </style> 23 </head> 24 25 <body> 26 <form name="myform" id="myform" method="post" action="<?php echo $_SERVER['PHP_SELF'];?>"> 27 <h1 style="color:#2583ad;">在线压缩ZIP文件程序</h1><br> 28 29 <div class="message"> 30 <p>使用方法:选定要压缩的文件或目录(包含子目录),即可开始压缩。压缩的结果保留原来的目录结构。<br /> 31 <?php if(isset($_REQUEST['pwd']) && md5($_REQUEST['pwd']) == $password) 32 echo '当前目录:<span class="currentdir">'. dirname(__FILE__) . '</span> <a href="'. 33 $_SERVER['PHP_SELF']. '">退出</a>'; 34 else 35 if(isset($_GET['pwd']) ) 36 echo '密码值:<span class="currentdir">'. md5($_GET['pwd']) . '</span>'; 37 else 38 echo 'Tips:在URL后参加<span class="currentdir">?pwd=密码</span> 查看生成密码.'; 39 ?> 40 </p> 41 </div> 42 <? 43 if(!isset($_REQUEST["myaction"])): 44 ?> 45 <table width="100%" border="0" cellspacing="0" cellpadding="0"> 46 <tr> 47 <td width="11%">验证密码: </td> 48 <td width="89%"><input name="pwd" type="password" id="password" size="30" onkeydown="if(event.ctrlKey&&event.keyCode==13){document.getElementById('login').click();return false};"></td> 49 </tr> 50 <tr> 51 <td><input name="myaction" type="hidden" id="myaction" value="dolist"></td> 52 <td><input type="submit" name="Submit" id="login" class="button" value=" 进 入 "></td> 53 </tr> 54 </table> 55 <script type="text/javascript"> 56 document.getElementById('password').focus(); 57 </script> 58 <? 59 60 elseif($_REQUEST["myaction"]=="dolist"): 61 62 if(!isset($_REQUEST['pwd']) || empty($_REQUEST['pwd']) ) 63 die('请输入密码! <a href="'. $_SERVER['PHP_SELF']. '">Again</a>'); 64 if(md5($_REQUEST['pwd']) != $password) 65 die('输入的密码不正确!<a href="'. $_SERVER['PHP_SELF']. '">Again</a>'); 66 echo '选择要排除的目录(相对路径,以英文半角逗号分隔):<br />'; 67 echo '<input type="text" id="toexlude" name="toexlude" size="100" /><br />'; 68 echo "选择要压缩的文件或目录:<br/>"; 69 $fdir = opendir('./'); 70 while($file=readdir($fdir)){ 71 if($file=='.'|| $file=='..' ) continue; 72 echo "<input name='dfile[]' type='checkbox' value='$file' ".($file==basename(__FILE__)?"":"checked")."> "; 73 if(is_file($file)){ 74 echo "<span class='myfilename'>文件: $file</span><br>"; 75 }else{ 76 echo "<span class='mydirname'>目录: $file</span><br>"; 77 } 78 } 79 ?> 80 <br> 81 压缩文件保存到目录: 82 <input name="todir" type="text" id="todir" value="_zipfiles<?php echo substr(md5(time()),0,8);?>_" size="20"> 83 (留空为本目录,必须有写入权限)<br> 84 压缩文件名称: 85 <input name="zipname" type="text" id="zipname" value="backup_<?php echo substr(md5(__FILE__),0,8);?>.zip" size="15"> 86 (.zip)<br> 87 <br> 88 <input name="pwd" type="hidden" id="password" value="<?php echo $_POST['pwd'];?>"> 89 <input name="myaction" type="hidden" id="myaction" value="dozip"> 90 <input type='button' value='反选' onclick='selrev();'> 91 <input type="submit" name="Submit" value=" 开始压缩 "> 92 <script language='javascript'> 93 function selrev() { 94 with(document.getElementById('myform')){ 95 for(i=0;i<elements.length;i++) { 96 thiselm = elements[i]; 97 if(thiselm.name.match(/dfile\[]/)) thiselm.checked = !thiselm.checked; 98 } 99 } 100 } 101 </script> 102 <? 103 104 elseif($_REQUEST["myaction"]=="dozip"): 105 106 // set_time_limit(0); 107 108 class PHPzip{ 109 110 var $file_count = 0 ; 111 var $datastr_len = 0; 112 var $dirstr_len = 0; 113 var $filedata = ''; //该变量只被类外部程序访问 114 var $gzfilename; 115 var $fp; 116 var $dirstr=''; 117 /* 118 返回文件的修改时间格式. 119 只为本类内部函数调用. 120 */ 121 function unix2DosTime($unixtime = 0) { 122 $timearray = ($unixtime == 0) ? getdate() : getdate($unixtime); 123 124 if ($timearray['year'] < 1980) { 125 $timearray['year'] = 1980; 126 $timearray['mon'] = 1; 127 $timearray['mday'] = 1; 128 $timearray['hours'] = 0; 129 $timearray['minutes'] = 0; 130 $timearray['seconds'] = 0; 131 } 132 133 return (($timearray['year'] - 1980) << 25) | ($timearray['mon'] << 21) | ($timearray['mday'] << 16) | 134 ($timearray['hours'] << 11) | ($timearray['minutes'] << 5) | ($timearray['seconds'] >> 1); 135 } 136 137 /* 138 初始化文件,建立文件目录, 139 并返回文件的写入权限. 140 */ 141 function startfile($path = 'myzip.zip'){ 142 $this->gzfilename=$path; 143 $mypathdir=array(); 144 do{ 145 $mypathdir[] = $path = dirname($path); 146 }while($path != '.'); 147 @end($mypathdir); 148 do{ 149 $path = @current($mypathdir); 150 @mkdir($path); 151 }while(@prev($mypathdir)); 152 153 if($this->fp=@fopen($this->gzfilename,"w")){ 154 return true; 155 } 156 return false; 157 } 158 159 /* 160 添加一个文件到 zip 压缩包中. 161 */ 162 function addfile($data, $name){ 163 $name = str_replace('\\', '/', $name); 164 165 if(strrchr($name,'/')=='/') return $this->adddir($name); 166 167 $dtime = dechex($this->unix2DosTime()); 168 $hexdtime = '\x' . $dtime[6] . $dtime[7] 169 . '\x' . $dtime[4] . $dtime[5] 170 . '\x' . $dtime[2] . $dtime[3] 171 . '\x' . $dtime[0] . $dtime[1]; 172 eval('$hexdtime = "' . $hexdtime . '";'); 173 174 $unc_len = strlen($data); 175 $crc = crc32($data); 176 $zdata = gzcompress($data); 177 $c_len = strlen($zdata); 178 $zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2); 179 180 //新添文件内容格式化: 181 $datastr = "\x50\x4b\x03\x04"; 182 $datastr .= "\x14\x00"; // ver needed to extract 183 $datastr .= "\x00\x00"; // gen purpose bit flag 184 $datastr .= "\x08\x00"; // compression method 185 $datastr .= $hexdtime; // last mod time and date 186 $datastr .= pack('V', $crc); // crc32 187 $datastr .= pack('V', $c_len); // compressed filesize 188 $datastr .= pack('V', $unc_len); // uncompressed filesize 189 $datastr .= pack('v', strlen($name)); // length of filename 190 $datastr .= pack('v', 0); // extra field length 191 $datastr .= $name; 192 $datastr .= $zdata; 193 $datastr .= pack('V', $crc); // crc32 194 $datastr .= pack('V', $c_len); // compressed filesize 195 $datastr .= pack('V', $unc_len); // uncompressed filesize 196 197 198 fwrite($this->fp,$datastr); //写入新的文件内容 199 $my_datastr_len = strlen($datastr); 200 unset($datastr); 201 202 //新添文件目录信息 203 $dirstr = "\x50\x4b\x01\x02"; 204 $dirstr .= "\x00\x00"; // version made by 205 $dirstr .= "\x14\x00"; // version needed to extract 206 $dirstr .= "\x00\x00"; // gen purpose bit flag 207 $dirstr .= "\x08\x00"; // compression method 208 $dirstr .= $hexdtime; // last mod time & date 209 $dirstr .= pack('V', $crc); // crc32 210 $dirstr .= pack('V', $c_len); // compressed filesize 211 $dirstr .= pack('V', $unc_len); // uncompressed filesize 212 $dirstr .= pack('v', strlen($name) ); // length of filename 213 $dirstr .= pack('v', 0 ); // extra field length 214 $dirstr .= pack('v', 0 ); // file comment length 215 $dirstr .= pack('v', 0 ); // disk number start 216 $dirstr .= pack('v', 0 ); // internal file attributes 217 $dirstr .= pack('V', 32 ); // external file attributes - 'archive' bit set 218 $dirstr .= pack('V',$this->datastr_len ); // relative offset of local header 219 $dirstr .= $name; 220 221 $this->dirstr .= $dirstr; //目录信息 222 223 $this -> file_count ++; 224 $this -> dirstr_len += strlen($dirstr); 225 $this -> datastr_len += $my_datastr_len; 226 } 227 228 function adddir($name){ 229 $name = str_replace("\\", "/", $name); 230 $datastr = "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00"; 231 232 $datastr .= pack("V",0).pack("V",0).pack("V",0).pack("v", strlen($name) ); 233 $datastr .= pack("v", 0 ).$name.pack("V", 0).pack("V", 0).pack("V", 0); 234 235 fwrite($this->fp,$datastr); //写入新的文件内容 236 $my_datastr_len = strlen($datastr); 237 unset($datastr); 238 239 $dirstr = "\x50\x4b\x01\x02\x00\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00"; 240 $dirstr .= pack("V",0).pack("V",0).pack("V",0).pack("v", strlen($name) ); 241 $dirstr .= pack("v", 0 ).pack("v", 0 ).pack("v", 0 ).pack("v", 0 ); 242 $dirstr .= pack("V", 16 ).pack("V",$this->datastr_len).$name; 243 244 $this->dirstr .= $dirstr; //目录信息 245 246 $this -> file_count ++; 247 $this -> dirstr_len += strlen($dirstr); 248 $this -> datastr_len += $my_datastr_len; 249 } 250 251 252 function createfile(){ 253 //压缩包结束信息,包括文件总数,目录信息读取指针位置等信息 254 $endstr = "\x50\x4b\x05\x06\x00\x00\x00\x00" . 255 pack('v', $this -> file_count) . 256 pack('v', $this -> file_count) . 257 pack('V', $this -> dirstr_len) . 258 pack('V', $this -> datastr_len) . 259 "\x00\x00"; 260 261 fwrite($this->fp,$this->dirstr.$endstr); 262 fclose($this->fp); 263 } 264 } 265 266 267 if(!trim($_REQUEST['zipname'])) 268 $_REQUEST['zipname'] = 'backup_'.substr(md5(__FILE__),0,8). '.zip'; 269 else 270 $_REQUEST['zipname'] = trim($_REQUEST['zipname']); 271 if(!strrchr(strtolower($_REQUEST['zipname']),'.')=='.zip') 272 $_REQUEST['zipname'] .= ".zip"; 273 $_REQUEST['todir'] = str_replace('\\','/',trim($_REQUEST['todir'])); 274 if(!strrchr(strtolower($_REQUEST['todir']),'/')=='/') 275 $_REQUEST['todir'] .= "/"; 276 if($_REQUEST['todir']=="/") 277 $_REQUEST['todir'] = "./"; 278 279 function listfiles($dir="."){ 280 global $faisunZIP; 281 $sub_file_num = 0; 282 283 if(is_file($dir)){ 284 if(realpath($faisunZIP->gzfilename)!=realpath($dir)){ 285 $faisunZIP -> addfile(implode('',file($dir)),$dir); 286 return 1; 287 } 288 return 0; 289 } 290 291 $handle=opendir($dir); 292 //添加排除 293 $to_exlude = !empty($_POST['toexlude']) ? $_POST['toexlude'] :''; 294 $exlude = empty($to_exlude) ? array() : explode(',',$to_exlude); 295 while ($file = readdir($handle)) { 296 if($file=="."||$file==".." || $file == 'wp-content' )continue; 297 if(is_dir("$dir/$file") && !in_array("$dir/$file",$exlude) ) 298 { 299 $sub_file_num += listfiles("$dir/$file"); 300 } 301 else { 302 if(realpath($faisunZIP ->gzfilename)!=realpath("$dir/$file")){ 303 $faisunZIP -> addfile(implode('',file("$dir/$file")),"$dir/$file"); 304 $sub_file_num ++; 305 } 306 } 307 } 308 closedir($handle); 309 if(!$sub_file_num) $faisunZIP -> addfile("","$dir/"); 310 return $sub_file_num; 311 } 312 313 function num_bitunit($num){ 314 $bitunit=array(' B',' KB',' MB',' GB'); 315 for($key=0;$key<count($bitunit);$key++){ 316 if($num>=pow(2,10*$key)-1){ //1023B 会显示为 1KB 317 $num_bitunit_str=(ceil($num/pow(2,10*$key)*100)/100)." $bitunit[$key]"; 318 } 319 } 320 return $num_bitunit_str; 321 } 322 323 if(is_array($_REQUEST['dfile'])){ 324 $faisunZIP = new PHPzip; 325 if($faisunZIP -> startfile($_REQUEST['todir'].$_REQUEST['zipname'])){ 326 echo "正在添加压缩文件...<br><br>"; 327 $filenum = 0; 328 foreach($_REQUEST['dfile'] as $file){ 329 if(is_file($file)){ 330 echo "<span class='myfilename'>文件: $file </span><br>"; 331 }else{ 332 echo "<span class='mydirname'>目录: $file </span><br>"; 333 } 334 $filenum += listfiles($file); 335 } 336 $faisunZIP -> createfile(); 337 echo "<br>压缩完成,共添加 $filenum 个文件.<br /><a href='" .$_REQUEST['todir'].$_REQUEST['zipname']. "'>". $_REQUEST['todir'].$_REQUEST['zipname']." (".num_bitunit(filesize("$_REQUEST[todir]$_REQUEST[zipname]")).")</a>"; 338 }else{ 339 echo $_REQUEST['todir'].$_REQUEST['zipname'].'不能写入,请检查路径或权限是否正确.<br>'; 340 } 341 }else{ 342 echo "没有选择的文件或目录.<br>"; 343 } 344 345 346 endif; 347 348 ?> 349 </form> 350 <div id="footer"> 351 <p><a href="http://ihacklog.com/" target="_blank">荒野无灯</a> (修改) <a href="javascript:;" onclick="scrollTo(0,0);" title="返回顶部">TOP</a></p> 352 </div> 353 </body> 354 </html>
比你优秀的人不可怕,可怕的是比你优秀的人比你更努力