码迷,mamicode.com
首页 > Web开发 > 详细

php添加文件到压缩文件夹

时间:2015-05-11 14:14:38      阅读:164      评论:0      收藏:0      [点我收藏+]

标签:

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文件。文件会在用户下载完成后被删除

php添加文件到压缩文件夹

标签:

原文地址:http://www.cnblogs.com/liuwenbohhh/p/4494204.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!