extension=php_zip.dll注释掉
<?php
$filename = "test.zip";
ob_end_clean();
$zip = new ZipArchive();
$zip->open($filename, ZipArchive::OVERWRITE);
$func=dirname(__FILE__)."/test/";
$attachfile = $func."test.txt";//写绝对径,建议用PHP环境变量
// $attachfile=iconv("UTF-8","GBK",$attachfile); //转码,打包中文文档
$zip->addFile( $attachfile , basename($attachfile)); //把文件放入zip
$zip->addFile( $attachfile , basename( $func."test1.txt"));
$zip->close();//关闭
header('Content-Description: File Transfer');
Header("content-type:application/x-zip-compressed");
header('Content-Disposition: attachment; filename='.basename($filename));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($filename));
ob_clean(); //清空但不关闭输出缓存
flush();
@readfile($filename);
@unlink($filename);//删除打包的临时zip文件。文件会在用户下载完成后被删除