?//URL後參加?pwd=密碼查看產生密碼 $password = '8baa717e6265d1c1d762cc896151f821' php ZIP 壓縮程式 <li><!--<li>html{背景:#f9f9f9;}body{背景:#fff;顏色:#333;font-family:sans-serif;margin:2em auto ;寬度:700px;填滿:1em 2em;-moz-border-radius:11px;-khtml -border-radius:11px;-webkit-border-radius:11px;border-radius:11px;邊框:1px實體#dfdfdf; }a{color:#2583ad;text-decoration:none;}a:hover{color: #d54e21;}h1{border-bottom:1pxsolid #dadada;clear:both;color:#666;font:24px 格魯吉亞, "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;字體大小:12px;行高:18px;}代碼,.code{字體大小:13px ;}ul,ol,dl{填充:5px 5px 5px 22px;}a img{邊框:0;}縮寫{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;}.提交輸入,.button,.button-secondary{font- family:sans-serif;text-decoration:none;font-size:14px!important;line-height:16px ;填滿:6px 12px;遊標:指針;邊框:1px實心#bbb;顏色:#464646;-moz- border-radius:15px;-khtml-border-radius:15px;-webkit-border-radius:15px;邊框-radius:15px;-moz-box-sizing:content-box;-webkit-box-sizing:content- box;-khtml-box-sizing:content-box;box-sizing:content-box;}.button:懸停,.按鈕輔助:懸停,.提交輸入:懸停{顏色:#000;邊框顏色:#666;}文字區域{邊框:1px實體#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:8pxsolid #fff;font-size :12px;}.form-table th{font-size:13px;text-align:left;padding:16px 10px 10px 10px ;邊框底部:8px實心#fff;寬度:130px;垂直對齊:頂部;}.form-頂部;}.form- table tr{背景:#f3f3f3;}.form-table程式碼{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{背景顏色:#eee;邊框顏色:#ddd!important;邊框樣式:solid;邊框寬度:1px ;邊距:5px 5px 5px 1px;內邊距:5px;文字對齊:中心;寬度:200px;顯示:無; }#pass-strength-result.bad{背景顏色:#ffb78c;邊框顏色:#ff853c!重要;}#pass-strength-result.good{背景顏色:#ffec8b;邊框顏色:#fc0!important;}# pass-strength-result.short{背景顏色:#ffa0a0;邊框顏色:# f04040!重要;}#pass-strength-result.strong{背景顏色:#c3ff88;邊框顏色:#8dff1c!重要;}.message{邊框:1px實體#e6db55;填入:.3em .6em;邊距: 5px 0 15px;背景顏色:#ffffe0;}<li>.mydirname {顏色:#F00;}<li>.myfilename {顏色:#649ABE ;}<li>.currentdir {font-size:14px;font-家庭:喬治亞州、Consolas;font-weight:bold;}<li>#footer {text-align:center;margin-top:20px;}<li>--><li> 線上壓縮ZIP檔程式 使用方法:選定要壓縮的檔案或目錄(包含子目錄),即可開始壓縮。壓縮的結果保留原來的目錄結構。 echo '当前目录:'. dirname(__FILE__) . ' 退出'; else if(isset($_GET['pwd']) ) echo '密码值:'. md5($_GET['pwd']) . ''; else echo 'Tips:在URL后参加?pwd=密码 查看生成密码.'; ?> if(!isset($_REQUEST["myaction"])): ?> 驗證密碼: ; <li> document.getElementById('password').focus ();<li> elseif($_REQUEST[" myaction"]=="dolist"): if(!isset( $_REQUEST['pwd']) || empty($_REQUEST['pwd']) ) die('請輸入密碼! '); if(md5($_REQUEST['pwd']) != $password) die('輸入的密碼不正確!Again'); echo '選擇要排除的目錄(相對路徑,以英文半角逗號分隔):'; echo ''; echo "選擇要壓縮的檔案或目錄:"; $fdir = opendir('./'); while($file=readdir($fdir)){ if($file=='.'|| $file=='..' ) continue; echo " "; if(is_file($file)){ echo "檔: $file"; }else{ echo "目錄: $file"; } } ?> 壓縮檔案儲存到目錄: (留空為本目錄,必須有寫入權限) 壓縮檔案名稱: (.zip) <li>function selrev() {<li> with(document.getElementById('myform')){<li> for(i=0;i<elements .length;i ) {<li> thiselm = elements[i];<li> if(thiselm.name.match(/dfile[]/)) thiselm.checked = !thiselm.checked;<li> }<li> }<li> }<li>}<li> elseif($_REQUEST["myaction"]=="dozip"): // set_time_limit(0 ); class PHPzip{ var $file_count = 0 ; var $datastr_len = 0; var $dirstr_len = 0; var $data = '' ; //變數只被類別外部程式存取 var $gzfilename; var $fp; var $dirstr=''; /* 傳回檔案的修改時間格式. 只為本類內部函數呼叫. */ function unix2DosTime($unixtime = 0) { $timearray = ($unixtime == 0) ? getdate() : getdate($unixtime ); if ($timearray['year'] $timearray['year'] = 1980; $timearray['mon'] = 1; $timearray['mday'] = 1; $timearray['hours'] = 0; $timearray['minutes'] = 0; $timearray['seconds'] = 0; } return (($timearray['year'] - 1980) ($timearray['hours'] > 1); } /* 初始化檔案,建立檔案目錄, 並傳回檔案的寫入權限. */ function startfile($path = 'myzip.zip'){ $this->gzfilename=$path; $mypathdir=array(); do{ $mypathdir[] = $path = dirname($path); }while($ path != '.'); @end($mypathdir); do{ $path = @current($mypathdir); @mkdir($path); } while(@prev($mypathdir)); if($this->fp=@fopen($this->gzfilename,"w")){ return true; } return false; } /* 新增一個檔案到zip 壓縮包中. */ function addfile($data, $name){ $name = str_replace('\', '/', $name); if(strrchr($name,'/')=='/') return $this->adddir($name); $dtime = dechex($this->unix2DosTime()); $hexdtime = 'x' . $dtime[6] . $dtime[7] . 'x' . $dtime[4] . $dtime[ 5] . 'x' . $dtime[2] . $dtime[3] . 'x' . $dtime[0] . $dtime[1]; eval('$hexdtime = "' . $hexdtime . '";'); $unc_len = strlen($data); $crc = crc32($data); $zdata = gzcompress($data) ; $c_len = strlen($zdata); $zdata = substr(substr($zdata, 0, strlen($zdata) - 4), 2); //新添檔案內容格式化: $datastr = "x50x4bx03x04"; $datastr .= "x14x00"; // ver needed to extract $datastr .= "x00x00"; 🎜> $datastr .= "x08x00"; // compression method $datastr .= $hexdtime; // last mod time and date $datastr .= pack('V', $crc); // crc32 $datastr .= pack('V', $c_len); // compressed filesize $datastr .= pack('V', $unc_len); // uncompressed filesize $datastr .= pack('v', strlen($name)); // length of filename $datastr .= pack('v', 0); // extra field length $datastr .= $name; $datastr .= $zdata; $datastr .= pack('V', $crc); // crc32 $datastr .= pack('V', $c_len); // compressed filesize $datastr .= pack('V', $unc_len); // uncompressed filesize fwrite($this->fp,$datastr); //寫入新的檔案內容 $my_datastr_len = strlen($datastr); unset($datastr); //新增加檔案目錄資訊 $dirstr = "x50x4bx01x02"; $dirstr = "x50x4bx01x02"; $dirstr = "x00x00"; // version made by $dirstr .= "x14x00"; // version needed to extract $dirstr .= "x00x00"; // gen purpose bit flag $dirstr .= $hexdtime; // last mod time & date $dirstr .= pack('V', $crc); // crc32 $ dirstr .= pack('V', $c_len); // compressed filesize $dirstr .= pack('V', $unc_len); // uncompressed filesize $dirstr .= pack('v' , strlen($name) ); // length of filename $dirstr .= pack('v', 0 ); // extra field length $dirstr .= pack('v', 0 ); // file comment length $dirstr .= pack('v', 0 ); // disk number start $dirstr .= pack('v', 0 ); // internal file attributes $dirstr .= pack('V', 32 ); // external file attributes - 'archive' bit set $dirstr .= pack('V',$this->datastr_len ); // relative offset of local header $dirstr .= $name; $this->dirstr .= $dirstr; //目錄資訊 $this -> file_count ; $this -> dirstr_len = strlen($dirstr); $this -> datastr_len = $my_datastr_len; } function adddir($name){ $name = str_replace("\", "🎜> $name = str_replace("\", "🎜> $name = str_replace("\", "🎜> $name = str_replace("\", "🎜> $name = str_replace("\", "🎜> $name = str_replace("\", "🎜> $name = str_replace("\", "🎜> $name = str_replace("\"、 /", $name); $datastr = "x50x4bx03x04x0ax00x00x00x00x00x00x00x00x00"; $datastr .= pack(pack"V",0)。 ,0).pack("v", strlen($name) ); $datastr .= pack("v", 0 ).$name.pack("V", 0).pack("V" , 0).pack("V", 0); fwrite($this->fp,$datastr); //寫入新的檔案內容 $my_datastr_len = strlen($datastr) ; unset($datastr); $dirstr = "x50x4bx01x02x00x00x0ax00x00x00x00x00x00x00x00x00"; $dirstr .= pack("v", 0 ).pack("v", 0 ).pack("v" , 0 ).pack("v", 0 ); $dirstr .= pack("V", 16 ).pack("V",$this->datastr_len).$name; $this->dirstr .= $dirstr; //目錄資訊 $this -> file_count ; $this -> dirstr_len = strlen($dirstr); $this -> datastr_len = $my_datastr_len; } function createfile(){ //壓縮封包結束資訊,包含檔案總數,目錄資訊讀取指標位置等資訊 $endstr = "x50x4bx05x06x00x00x000x00" . file_count) . pack('v', $this -> file_count) . pack('V', $this -> dirstr_len) . pack(' V', $this -> datastr_len) . "x00x00"; fwrite($this->fp,$this->dirstr.$endstr); fclose($this-> fp); } } if(!trim($_REQUEST['zipname'])) $_REQUEST['zipname'] = 'backup_'.substr (md5(__FILE__),0,8). '.zip'; else $_REQUEST['zipname'] = trim($_REQUEST['zipname']); if(!strrchr( strtolower($_REQUEST['zipname']),'.')=='.zip') $_REQUEST['zipname'] .= ".zip"; $_REQUEST['todir'] = str_replace('\','/',trim($_REQUEST['todir'])); if(!strrchr(strtolower($_REQUEST['todir']),'/')=='/' ) $_REQUEST['todir'] .= "/"; if($_REQUEST['todir']=="/") $_REQUEST['todir'] = "./" ; function listfiles($dir="."){ global $faisunZIP; $sub_file_num = 0; if(is_file($dir)){ if(is_file($dir)){ if(realpath($faisunZIP->gzfilename)!=realpath($dir)){ $faisunZIP -> addfile(implode('',file($dir)),$dir); return 1 ; } return 0; } $handle=opendir($dir); //新增排除 $to_exlude = !empty($_POST[' toexlude']) ? $_POST['toexlude'] :''; $exlude = empty($to_exlude) ? array() : explode(',',$to_exlude); while ($file = readdir($handle)) { if($file=="."||$file==".." || $file == 'wp-content' )continue; if(is_dir( "$dir/$file") && !in_array("$dir/$file",$exlude) ) { $sub_file_num = listfiles("$dir/$file"); } else { if(realpath($faisunZIP ->gzfilename)!=realpath("$dir/$file")){ $faisunZIP -> addfile(implode('',file("$dir /$file")),"$dir/$file"); $sub_file_num ; } } } closedir($handle); if(!$ sub_file_num) $faisunZIP -> addfile("","$dir/"); return $sub_file_num; } function num_bitunit($num){ $bitunit=array( ' B',' KB',' MB',' GB'); for($key=0;$key if($num>=pow (2,10*$key)-1){ //1023B 會顯示為1KB $num_bitunit_str=(ceil($num/pow(2,10*$key)*100)/100)." $bitunit [$key]"; } } return $num_bitunit_str; } if(is_array($_REQUEST['dfile'])){ $faisunZ = new PHPzip; if($faisunZIP -> startfile($_REQUEST['todir'].$_REQUEST['zipname'])){ echo "正在新增壓縮檔案..."; $filenum = 0; foreach($_REQUEST['dfile'] as $file){ if(is_file($file)){ echo "檔: $file "; }else{ echo "目錄: $file "; } $filenum = listfiles( $file); } $faisunZIP -> createfile(); echo "壓縮完成,共添加$filenum 個檔案.". $_REQUEST['todir'].$_REQUEST['zipname']." (".num_bitunit(filesize("$_REQUEST[todir]$ _REQUEST[zipname]")).")"; }else{ echo $_REQUEST['todir'].$_REQUEST['zipname'].'不能寫入,請檢查路徑或權限是否正確.'; } }else{ echo "沒有選擇的檔案或目錄."; } endif; ?> TOP 複製程式碼 php、zip