日期:2012-01-19  浏览次数:20745 次

效果图:

PHP代码

复制代码 代码如下:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>网站程序备份</title>
</head>
<body>
<form name="myform" method="post" action="">
<?php
error_reporting(E_ALL & ~E_NOTICE);
ini_set("memory_limit", "2048M");
echo "选择要压缩的文件或目录:<br>";
$fdir = opendir("./");
while($file=readdir($fdir))
{
if($file=="." $file=="..")
continue;
echo "<input name="dfile[]" type="checkbox" value="$file" ".($file==basename(__FILE__)?"":"checked")."> ";
if(is_file($file))
{
echo "<font face=\"wingdings\" size=\"5\">2</font> $file<br>";
}
else
{
echo "<font face=\"wingdings\" size=\"5\">0</font> $file<br>";
}
}
?>
<br>
包含下列文件类型:
<input name="file_type" type="text" id="file_type" value="" size="50">
<font color="red">
(文件类型用""隔开,默认空则包含任意文件,例:如果需要打包php和jpg文件,则输入"phpjpg")
</font>
<br>
压缩文件保存到目录:
<input name="todir" type="text" id="todir" value="__dwb2011__" size="15">
<font color="red">
(留空为本目录,必须有写入权限)
</font>
<br>
压缩文件名称:
<input name="zipname" type="text" id="zipname" value="dwb2011.zip" size="15">
<font color="red">
(.zip)
</font>
<br>
<br>
<input name="myaction" type="hidden" id="myaction" value="dozip">
<input type="button" value="反选" >
<input type="submit" name="Submit" value=" 开始压缩 ">
<script language="javascript">
function selrev()
{
with(document.myform)
{
for(i=0;i<elements.length;i++)
{
thiselm = elements[i];
if(thiselm.name.match(/dfile\[]/))
thiselm.checked = !thiselm.checked;
}
}
}
</script>
<?php
error_reporting(E_ALL & ~E_NOTICE);
set_time_limit(0);
class PHPzip
{
var $file_count = 0 ;
var $datastr_len = 0;
var $dirstr_len = 0;
var $filedata = ""; //该变量只被类外部程序访问
var $gzfilename;
var $fp;
var $dirstr="";
var $filefilters = array();
function SetFileFilter($filetype)
{
$this->filefilters = explode("",$filetype);
}
//返回文件的修改时间格式.
//只为本类内部函数调用.
function unix2DosTime($unixtime = 0)
{
$timearray = ($unixtime == 0) ? getdate() : getdate($unixtime);
if ($timearray["year"] < 1980)
{
$timearray["year"] = 1980;
$timearray["mon"] = 1;
$timearray["mday"] = 1;
$timearray["hours"] = 0;
$timearray["minutes"] = 0;
$timearray["seconds"] = 0;
}
return (($timearray["year"] - 1980) << 25) ($timearray["mon"] << 21) ($timearray["mday"] << 16) ($timearray["hours"] << 11) ($timearray["minutes"] << 5) ($timearray["seconds"] >> 1);
}
//初始化文件,建立文件目录,
//并返回文件的写入权限.
function startfile($path = "dodo.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->addd