php部分,记得加上头
// 应用入口文件
header("Content-Type: text/html; charset=utf-8");
error_reporting(0);
$button=$_POST['button'];
if($button=="开始打包")
{
$zip = new ZipArchive();
$filename = "./".date("Y-m-d")."_".md5(time())."_back.zip";
if ($zip->open($filename, ZIPARCHIVE::CREATE)!==TRUE) {
exit("无法创建 \n");
}
$files = listdir();
foreach($files as $path)
{
$zip->addFile($path,str_replace("./","",str_replace("\\","/",$path)));
}
echo "压缩完成,共压缩了: " . $zip->numFiles . "个文件\n";
$zip->close();
}
Function listdir($start_dir='.') {
$files = array();
if (is_dir($start_dir)) {
$fh = opendir($start_dir);
while (($file = readdir($fh)) !== false) {
if (strcmp($file, '.')==0 || strcmp($file, '..')==0) continue;
$filepath = $start_dir . '/' . $file;
if ( is_dir($filepath) )
$files = array_merge($files, listdir($filepath));
else
array_push($files, $filepath);
}
closedir($fh);
} else {
$files = false;
}
return $files;
}
?>
html部分,记得用<替换<\:
<\!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<\html>
<\head>
<\title>php在线打包工具<\/title>
<\meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<\/head>
<\body>
<\form name="form1" method="post" action="">
<\hr size="1">
<\h3><\a href="?">在线打包工具<\/a><\/h3>
<\P> <\input type="submit" name="button" value="开始打包" /><\/P>
<\P>说明:点开始打包,耐心等待 ftp后下载。<\/P>
<\/form>
<\/body>
<\/html>