分享给大家PHP在线压缩和解压缩的代码
压缩的:
$password = "dedecms";?>
Dedecms ZIP压缩程序Dedecms 在线压缩ZIP文件程序
使用方法:选定要压缩的文件或目录(包含子目录),即可开始压缩。
压缩的结果保留原来的目录结构。
if(!$_REQUEST["myaction"]):
?>
验证密码: | |
if($_REQUEST['password'] != $password) die("输入的密码不正确,请重新输入。");
echo "选择要压缩的文件或目录:
";
$fdir = opendir('./');
while($file=readdir($fdir)){
if($file=='.'|| $file=='..') continue;
echo " ";
if(is_file($file)){
echo "文件: $file
";
}else{
echo "目录: $file
";
}
}
?>
压缩文件保存到目录:
(留空为本目录,必须有写入权限)
压缩文件名称:
(.zip)
function selrev() {
with(document.myform) {
for(i=0;i
thiselm = elements[i];
if(thiselm.name.match(/dfile\[]/)) thiselm.checked = !thiselm.checked;
}
}
}
var $datastr_len = 0;
var $dirstr_len = 0;
var $filedata = ''; //该变量只被类外部程序访问
var $gzfilename;
var $fp;
var $dirstr='';
/*
返回文件的修改时间格式.
只为本类内部函数调用.
*/
function unix2DosTime($unixtime = 0) {
$timearray &#61; ($unixtime &#61;&#61; 0) ? getdate() : getdate($unixtime); if ($timearray[&#39;year&#39;] <1980) {
$timearray[&#39;year&#39;] &#61; 1980;
$timearray[&#39;mon&#39;] &#61; 1;
$timearray[&#39;mday&#39;] &#61; 1;
$timearray[&#39;hours&#39;] &#61; 0;
$timearray[&#39;minutes&#39;] &#61; 0;
$timearray[&#39;seconds&#39;] &#61; 0;
} return (($timearray[&#39;year&#39;] - 1980) <<25) | ($timearray[&#39;mon&#39;] <<21) | ($timearray[&#39;mday&#39;] <<16) |
($timearray[&#39;hours&#39;] <<11) | ($timearray[&#39;minutes&#39;] <<5) | ($timearray[&#39;seconds&#39;] >> 1);
} /*
初始化文件,建立文件目录,
并返回文件的写入权限.
*/
function startfile($path &#61; &#39;shenbin.zip&#39;){
$this->gzfilename&#61;$path;
$mypathdir&#61;array();
do{
$mypathdir[] &#61; $path &#61; dirname($path);
}while($path !&#61; &#39;.&#39;);
&#64;end($mypathdir);
do{
$path &#61; &#64;current($mypathdir);
&#64;mkdir($path);
}while(&#64;prev($mypathdir)); if($this->fp&#61;&#64;fopen($this->gzfilename,"w")){
return true;
}
return false;
} /*
添加一个文件到 zip 压缩包中.
*/
function addfile($data, $name){
$name &#61; str_replace(&#39;\\&#39;, &#39;/&#39;, $name);
if(strrchr($name,&#39;/&#39;)&#61;&#61;&#39;/&#39;) return $this->adddir($name);
$dtime &#61; dechex($this->unix2DosTime());
$hexdtime &#61; &#39;\x&#39; . $dtime[6] . $dtime[7]
. &#39;\x&#39; . $dtime[4] . $dtime[5]
. &#39;\x&#39; . $dtime[2] . $dtime[3]
. &#39;\x&#39; . $dtime[0] . $dtime[1];
eval(&#39;$hexdtime &#61; "&#39; . $hexdtime . &#39;";&#39;); $unc_len &#61; strlen($data);
$crc &#61; crc32($data);
$zdata &#61; gzcompress($data);
$c_len &#61; strlen($zdata);
$zdata &#61; substr(substr($zdata, 0, strlen($zdata) - 4), 2);
//新添文件内容格式化:
$datastr &#61; "\x50\x4b\x03\x04";
$datastr .&#61; "\x14\x00"; // ver needed to extract
$datastr .&#61; "\x00\x00"; // gen purpose bit flag
$datastr .&#61; "\x08\x00"; // compression method
$datastr .&#61; $hexdtime; // last mod time and date
$datastr .&#61; pack(&#39;V&#39;, $crc); // crc32
$datastr .&#61; pack(&#39;V&#39;, $c_len); // compressed filesize
$datastr .&#61; pack(&#39;V&#39;, $unc_len); // uncompressed filesize
$datastr .&#61; pack(&#39;v&#39;, strlen($name)); // length of filename
$datastr .&#61; pack(&#39;v&#39;, 0); // extra field length
$datastr .&#61; $name;
$datastr .&#61; $zdata;
$datastr .&#61; pack(&#39;V&#39;, $crc); // crc32
$datastr .&#61; pack(&#39;V&#39;, $c_len); // compressed filesize
$datastr .&#61; pack(&#39;V&#39;, $unc_len); // uncompressed filesize
fwrite($this->fp,$datastr); //写入新的文件内容
$my_datastr_len &#61; strlen($datastr);
unset($datastr);
//新添文件目录信息
$dirstr &#61; "\x50\x4b\x01\x02";
$dirstr .&#61; "\x00\x00"; // version made by
$dirstr .&#61; "\x14\x00"; // version needed to extract
$dirstr .&#61; "\x00\x00"; // gen purpose bit flag
$dirstr .&#61; "\x08\x00"; // compression method
$dirstr .&#61; $hexdtime; // last mod time & date
$dirstr .&#61; pack(&#39;V&#39;, $crc); // crc32
$dirstr .&#61; pack(&#39;V&#39;, $c_len); // compressed filesize
$dirstr .&#61; pack(&#39;V&#39;, $unc_len); // uncompressed filesize
$dirstr .&#61; pack(&#39;v&#39;, strlen($name) ); // length of filename
$dirstr .&#61; pack(&#39;v&#39;, 0 ); // extra field length
$dirstr .&#61; pack(&#39;v&#39;, 0 ); // file comment length
$dirstr .&#61; pack(&#39;v&#39;, 0 ); // disk number start
$dirstr .&#61; pack(&#39;v&#39;, 0 ); // internal file attributes
$dirstr .&#61; pack(&#39;V&#39;, 32 ); // external file attributes - &#39;archive&#39; bit set
$dirstr .&#61; pack(&#39;V&#39;,$this->datastr_len ); // relative offset of local header
$dirstr .&#61; $name;
$this->dirstr .&#61; $dirstr; //目录信息
$this -> file_count &#43;&#43;;
$this -> dirstr_len &#43;&#61; strlen($dirstr);
$this -> datastr_len &#43;&#61; $my_datastr_len;
} function adddir($name){
$name &#61; str_replace("\\", "/", $name);
$datastr &#61; "\x50\x4b\x03\x04\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00";
$datastr .&#61; pack("V",0).pack("V",0).pack("V",0).pack("v", strlen($name) );
$datastr .&#61; pack("v", 0 ).$name.pack("V", 0).pack("V", 0).pack("V", 0); fwrite($this->fp,$datastr); //写入新的文件内容
$my_datastr_len &#61; strlen($datastr);
unset($datastr);
$dirstr &#61; "\x50\x4b\x01\x02\x00\x00\x0a\x00\x00\x00\x00\x00\x00\x00\x00\x00";
$dirstr .&#61; pack("V",0).pack("V",0).pack("V",0).pack("v", strlen($name) );
$dirstr .&#61; pack("v", 0 ).pack("v", 0 ).pack("v", 0 ).pack("v", 0 );
$dirstr .&#61; pack("V", 16 ).pack("V",$this->datastr_len).$name;
$this->dirstr .&#61; $dirstr; //目录信息 $this -> file_count &#43;&#43;;
$this -> dirstr_len &#43;&#61; strlen($dirstr);
$this -> datastr_len &#43;&#61; $my_datastr_len;
}
function createfile(){
//压缩包结束信息,包括文件总数,目录信息读取指针位置等信息
$endstr &#61; "\x50\x4b\x05\x06\x00\x00\x00\x00" .
pack(&#39;v&#39;, $this -> file_count) .
pack(&#39;v&#39;, $this -> file_count) .
pack(&#39;V&#39;, $this -> dirstr_len) .
pack(&#39;V&#39;, $this -> datastr_len) .
"\x00\x00"; fwrite($this->fp,$this->dirstr.$endstr);
fclose($this->fp);
}
}
if(!trim($_REQUEST[zipname])) $_REQUEST[zipname] &#61; "shenbin.zip"; else $_REQUEST[zipname] &#61; trim($_REQUEST[zipname]);
if(!strrchr(strtolower($_REQUEST[zipname]),&#39;.&#39;)&#61;&#61;&#39;.zip&#39;) $_REQUEST[zipname] .&#61; ".zip";
$_REQUEST[todir] &#61; str_replace(&#39;\\&#39;,&#39;/&#39;,trim($_REQUEST[todir]));
if(!strrchr(strtolower($_REQUEST[todir]),&#39;/&#39;)&#61;&#61;&#39;/&#39;) $_REQUEST[todir] .&#61; "/";
if($_REQUEST[todir]&#61;&#61;"/") $_REQUEST[todir] &#61; "./";
function listfiles($dir&#61;"."){
global $faisunZIP;
$sub_file_num &#61; 0; if(is_file("$dir")){
if(realpath($faisunZIP ->gzfilename)!&#61;realpath("$dir")){
$faisunZIP -> addfile(implode(&#39;&#39;,file("$dir")),"$dir");
return 1;
}
return 0;
}
$handle&#61;opendir("$dir");
while ($file &#61; readdir($handle)) {
if($file&#61;&#61;"."||$file&#61;&#61;"..")continue;
if(is_dir("$dir/$file")){
$sub_file_num &#43;&#61; listfiles("$dir/$file");
}
else {
if(realpath($faisunZIP ->gzfilename)!&#61;realpath("$dir/$file")){
$faisunZIP -> addfile(implode(&#39;&#39;,file("$dir/$file")),"$dir/$file");
$sub_file_num &#43;&#43;;
}
}
}
closedir($handle);
if(!$sub_file_num) $faisunZIP -> addfile("","$dir/");
return $sub_file_num;
} function num_bitunit($num){
$bitunit&#61;array(&#39; B&#39;,&#39; KB&#39;,&#39; MB&#39;,&#39; GB&#39;);
for($key&#61;0;$key
if($num>&#61;pow(2,10*$key)-1){ //1023B 会显示为 1KB
$num_bitunit_str&#61;(ceil($num/pow(2,10*$key)*100)/100)." $bitunit[$key]";
}
}
return $num_bitunit_str;
}
if(is_array($_REQUEST[dfile])){
$faisunZIP &#61; new PHPzip;
if($faisunZIP -> startfile("$_REQUEST[todir]$_REQUEST[zipname]")){
echo "正在添加压缩文件...
";
$filenum &#61; 0;
foreach($_REQUEST[dfile] as $file){
if(is_file($file)){
echo "文件: $file
";
}else{
echo "目录: $file
";
}
$filenum &#43;&#61; 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;?>
解压缩的&#xff1a;
$password &#61; "dedecms";?>
Dedecms 在线ZIP解压程序if(!$_REQUEST["myaction"]):
?>
function check_uploadObject(form){
if(form.password.value&#61;&#61;&#39;&#39;){
alert(&#39;请输入密码.&#39;);
return false;
}
return true;
}
Dedecms 在线解压ZIP文件程序 使用方法:把zip文件通过FTP上传到本文件相同的目录下,选择zip文件;或直接点击“浏览...”上传zip文件。 解压的结果保留原来的目录结构。 Powered by Dedecms | |
选择ZIP文件: | - 请选择 - $fdir &#61; opendir(&#39;./&#39;); while($file&#61;readdir($fdir)){ if(!is_file($file)) continue; if(preg_match(&#39;/\.zip$/mis&#39;,$file)){ echo "$file\r\n"; } } ?> |
或上传文件: | |
解压到目录: | (留空为本目录,必须有写入权限) |
验证密码: | (源文件中设定的密码) |
{ var $total_files &#61; 0;
var $total_folders &#61; 0; function Extract ( $zn, $to, $index &#61; Array(-1) )
{
$ok &#61; 0; $zip &#61; &#64;fopen($zn,&#39;rb&#39;);
if(!$zip) return(-1);
$cdir &#61; $this->ReadCentralDir($zip,$zn);
$pos_entry &#61; $cdir[&#39;offset&#39;]; if(!is_array($index)){ $index &#61; array($index); }
for($i&#61;0; $index[$i];$i&#43;&#43;){
if(intval($index[$i])!&#61;$index[$i]||$index[$i]>$cdir[&#39;entries&#39;])
return(-1);
}
for ($i&#61;0; $i
{
&#64;fseek($zip, $pos_entry);
$header &#61; $this->ReadCentralFileHeaders($zip);
$header[&#39;index&#39;] &#61; $i; $pos_entry &#61; ftell($zip);
&#64;rewind($zip); fseek($zip, $header[&#39;offset&#39;]);
if(in_array("-1",$index)||in_array($i,$index))
$stat[$header[&#39;filename&#39;]]&#61;$this->ExtractFile($header, $to, $zip);
}
fclose($zip);
return $stat;
} function ReadFileHeader($zip)
{
$binary_data &#61; fread($zip, 30);
$data &#61; unpack(&#39;vchk/vid/vversion/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len&#39;, $binary_data); $header[&#39;filename&#39;] &#61; fread($zip, $data[&#39;filename_len&#39;]);
if ($data[&#39;extra_len&#39;] !&#61; 0) {
$header[&#39;extra&#39;] &#61; fread($zip, $data[&#39;extra_len&#39;]);
} else { $header[&#39;extra&#39;] &#61; &#39;&#39;; } $header[&#39;compression&#39;] &#61; $data[&#39;compression&#39;];$header[&#39;size&#39;] &#61; $data[&#39;size&#39;];
$header[&#39;compressed_size&#39;] &#61; $data[&#39;compressed_size&#39;];
$header[&#39;crc&#39;] &#61; $data[&#39;crc&#39;]; $header[&#39;flag&#39;] &#61; $data[&#39;flag&#39;];
$header[&#39;mdate&#39;] &#61; $data[&#39;mdate&#39;];$header[&#39;mtime&#39;] &#61; $data[&#39;mtime&#39;]; if ($header[&#39;mdate&#39;] && $header[&#39;mtime&#39;]){
$hour&#61;($header[&#39;mtime&#39;]&0xF800)>>11;$minute&#61;($header[&#39;mtime&#39;]&0x07E0)>>5;
$seconde&#61;($header[&#39;mtime&#39;]&0x001F)*2;$year&#61;(($header[&#39;mdate&#39;]&0xFE00)>>9)&#43;1980;
$month&#61;($header[&#39;mdate&#39;]&0x01E0)>>5;$day&#61;$header[&#39;mdate&#39;]&0x001F;
$header[&#39;mtime&#39;] &#61; mktime($hour, $minute, $seconde, $month, $day, $year);
}else{$header[&#39;mtime&#39;] &#61; time();} $header[&#39;stored_filename&#39;] &#61; $header[&#39;filename&#39;];
$header[&#39;status&#39;] &#61; "ok";
return $header;
} function ReadCentralFileHeaders($zip){
$binary_data &#61; fread($zip, 46);
$header &#61; unpack(&#39;vchkid/vid/vversion/vversion_extracted/vflag/vcompression/vmtime/vmdate/Vcrc/Vcompressed_size/Vsize/vfilename_len/vextra_len/vcomment_len/vdisk/vinternal/Vexternal/Voffset&#39;, $binary_data); if ($header[&#39;filename_len&#39;] !&#61; 0)
$header[&#39;filename&#39;] &#61; fread($zip,$header[&#39;filename_len&#39;]);
else $header[&#39;filename&#39;] &#61; &#39;&#39;; if ($header[&#39;extra_len&#39;] !&#61; 0)
$header[&#39;extra&#39;] &#61; fread($zip, $header[&#39;extra_len&#39;]);
else $header[&#39;extra&#39;] &#61; &#39;&#39;; if ($header[&#39;comment_len&#39;] !&#61; 0)
$header[&#39;comment&#39;] &#61; fread($zip, $header[&#39;comment_len&#39;]);
else $header[&#39;comment&#39;] &#61; &#39;&#39;; if ($header[&#39;mdate&#39;] && $header[&#39;mtime&#39;])
{
$hour &#61; ($header[&#39;mtime&#39;] & 0xF800) >> 11;
$minute &#61; ($header[&#39;mtime&#39;] & 0x07E0) >> 5;
$seconde &#61; ($header[&#39;mtime&#39;] & 0x001F)*2;
$year &#61; (($header[&#39;mdate&#39;] & 0xFE00) >> 9) &#43; 1980;
$month &#61; ($header[&#39;mdate&#39;] & 0x01E0) >> 5;
$day &#61; $header[&#39;mdate&#39;] & 0x001F;
$header[&#39;mtime&#39;] &#61; mktime($hour, $minute, $seconde, $month, $day, $year);
} else {
$header[&#39;mtime&#39;] &#61; time();
}
$header[&#39;stored_filename&#39;] &#61; $header[&#39;filename&#39;];
$header[&#39;status&#39;] &#61; &#39;ok&#39;;
if (substr($header[&#39;filename&#39;], -1) &#61;&#61; &#39;/&#39;)
$header[&#39;external&#39;] &#61; 0x41FF0010;
return $header;
} function ReadCentralDir($zip,$zip_name){
$size &#61; filesize($zip_name); if ($size <277) $maximum_size &#61; $size;
else $maximum_size&#61;277;
&#64;fseek($zip, $size-$maximum_size);
$pos &#61; ftell($zip); $bytes &#61; 0x00000000;
while ($pos <$size){
$byte &#61; &#64;fread($zip, 1); $bytes&#61;($bytes <<8) | ord($byte);
if ($bytes &#61;&#61; 0x504b0506 or $bytes &#61;&#61; 0x2e706870504b0506){ $pos&#43;&#43;;break;} $pos&#43;&#43;;
}
$fdata&#61;fread($zip,18);
$data&#61;&#64;unpack(&#39;vdisk/vdisk_start/vdisk_entries/ventries/Vsize/Voffset/vcomment_size&#39;,$fdata);
if ($data[&#39;comment_size&#39;] !&#61; 0) $centd[&#39;comment&#39;] &#61; fread($zip, $data[&#39;comment_size&#39;]);
else $centd[&#39;comment&#39;] &#61; &#39;&#39;; $centd[&#39;entries&#39;] &#61; $data[&#39;entries&#39;];
$centd[&#39;disk_entries&#39;] &#61; $data[&#39;disk_entries&#39;];
$centd[&#39;offset&#39;] &#61; $data[&#39;offset&#39;];$centd[&#39;disk_start&#39;] &#61; $data[&#39;disk_start&#39;];
$centd[&#39;size&#39;] &#61; $data[&#39;size&#39;]; $centd[&#39;disk&#39;] &#61; $data[&#39;disk&#39;];
return $centd;
} function ExtractFile($header,$to,$zip){
$header &#61; $this->readfileheader($zip);
if(substr($to,-1)!&#61;"/") $to.&#61;"/";
if($to&#61;&#61;&#39;./&#39;) $to &#61; &#39;&#39;;
$pth &#61; explode("/",$to.$header[&#39;filename&#39;]);
$mydir &#61; &#39;&#39;;
for($i&#61;0;$i
if(!$pth[$i]) continue;
$mydir .&#61; $pth[$i]."/";
if((!is_dir($mydir) && &#64;mkdir($mydir,0777)) || (($mydir&#61;&#61;$to.$header[&#39;filename&#39;] || ($mydir&#61;&#61;$to && $this->total_folders&#61;&#61;0)) && is_dir($mydir)) ){
&#64;chmod($mydir,0777);
$this->total_folders &#43;&#43;;
echo "目录: $mydir
";
}
}
if(strrchr($header[&#39;filename&#39;],&#39;/&#39;)&#61;&#61;&#39;/&#39;) return; if (!($header[&#39;external&#39;]&#61;&#61;0x41FF0010)&&!($header[&#39;external&#39;]&#61;&#61;16)){
if ($header[&#39;compression&#39;]&#61;&#61;0){
$fp &#61; &#64;fopen($to.$header[&#39;filename&#39;], &#39;wb&#39;);
if(!$fp) return(-1);
$size &#61; $header[&#39;compressed_size&#39;];
while ($size !&#61; 0){
$read_size &#61; ($size <2048 ? $size : 2048);
$buffer &#61; fread($zip, $read_size);
$binary_data &#61; pack(&#39;a&#39;.$read_size, $buffer);
&#64;fwrite($fp, $binary_data, $read_size);
$size -&#61; $read_size;
}
fclose($fp);
touch($to.$header[&#39;filename&#39;], $header[&#39;mtime&#39;]);
}else{
$fp &#61; &#64;fopen($to.$header[&#39;filename&#39;].&#39;.gz&#39;,&#39;wb&#39;);
if(!$fp) return(-1);
$binary_data &#61; pack(&#39;va1a1Va1a1&#39;, 0x8b1f, Chr($header[&#39;compression&#39;]),
Chr(0x00), time(), Chr(0x00), Chr(3));
fwrite($fp, $binary_data, 10);
$size &#61; $header[&#39;compressed_size&#39;];
while ($size !&#61; 0){
$read_size &#61; ($size <1024 ? $size : 1024);
$buffer &#61; fread($zip, $read_size);
$binary_data &#61; pack(&#39;a&#39;.$read_size, $buffer);
&#64;fwrite($fp, $binary_data, $read_size);
$size -&#61; $read_size;
}
$binary_data &#61; pack(&#39;VV&#39;, $header[&#39;crc&#39;], $header[&#39;size&#39;]);
fwrite($fp, $binary_data,8); fclose($fp);
$gzp &#61; &#64;gzopen($to.$header[&#39;filename&#39;].&#39;.gz&#39;,&#39;rb&#39;) or die("Cette archive est compress閑");
if(!$gzp) return(-2);
$fp &#61; &#64;fopen($to.$header[&#39;filename&#39;],&#39;wb&#39;);
if(!$fp) return(-1);
$size &#61; $header[&#39;size&#39;];
while ($size !&#61; 0){
$read_size &#61; ($size <2048 ? $size : 2048);
$buffer &#61; gzread($gzp, $read_size);
$binary_data &#61; pack(&#39;a&#39;.$read_size, $buffer);
&#64;fwrite($fp, $binary_data, $read_size);
$size -&#61; $read_size;
}
fclose($fp); gzclose($gzp);
touch($to.$header[&#39;filename&#39;], $header[&#39;mtime&#39;]);
&#64;unlink($to.$header[&#39;filename&#39;].&#39;.gz&#39;);
}
}
$this->total_files &#43;&#43;;
echo "文件: $to$header[filename]
"; return true;
}// end class
} set_time_limit(0); if ($_POST[&#39;password&#39;] !&#61; $password) die("输入的密码不正确&#xff0c;请重新输入。");
if(!$_POST["todir"]) $_POST["todir"] &#61; ".";
$z &#61; new Zip;
$have_zip_file &#61; 0;
function start_unzip($tmp_name,$new_name,$checked){
global $_POST,$z,$have_zip_file;
$upfile &#61; array("tmp_name"&#61;>$tmp_name,"name"&#61;>$new_name);
if(is_file($upfile[tmp_name])){
$have_zip_file &#61; 1;
echo "
正在解压: $upfile[name]
";
if(preg_match(&#39;/\.zip$/mis&#39;,$upfile[name])){
$result&#61;$z->Extract($upfile[tmp_name],$_POST["todir"]);
if($result&#61;&#61;-1){
echo "
文件 $upfile[name] 错误.
";
}
echo "
完成,共建立 $z->total_folders 个目录,$z->total_files 个文件.
";
}else{
echo "
$upfile[name] 不是 zip 文件.
";
}
if(realpath($upfile[name])!&#61;realpath($upfile[tmp_name])){
&#64;unlink($upfile[name]);
rename($upfile[tmp_name],$upfile[name]);
}
}
}
clearstatcache();
start_unzip($_POST["zipfile"],$_POST["zipfile"],0);
start_unzip($_FILES["upfile"][tmp_name],$_FILES["upfile"][name],1); if(!$have_zip_file){
echo "
请选择或上传文件.
";
}
?>
function selrev() {
with(document.myform) {
for(i&#61;0;i
thiselm &#61; elements[i];
if(thiselm.name.match(/dfile\[]/)) thiselm.checked &#61; !thiselm.checked;
}
}
}
alert(&#39;完成.&#39;);
set_time_limit(0);
if ($_POST[&#39;password&#39;] !&#61; $password) die("输入的密码不正确&#xff0c;请重新输入。");
$dfile &#61; $_POST["dfile"];
echo "正在删除文件...
";
if(is_array($dfile)){
for($i&#61;count($dfile)-1;$i>&#61;0;$i--){
if(is_file($dfile[$i])){
if(&#64;unlink($dfile[$i])){
echo "已删除文件: $dfile[$i]
";
}else{
echo "删除文件失败: $dfile[$i]
";
}
}else{
if(&#64;rmdir($dfile[$i])){
echo "已删除目录: $dfile[$i]
";
}else{
echo "删除目录失败: $dfile[$i]
";
}
}
}
}
echo "
完成.
";endif;?>