php添加文件到压缩文件夹
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文件。文件会在用户下载完成后被删除
最新文章
- 前端构建工具之gulp(一)「图片压缩」
- MySql的一些用法
- UIWindow &; UIWindowLevel
- 在javascript中如何取消事件冒泡
- rc522 ,pn544区别
- POJ 1659 Frogs&#39; Neighborhood
- (五)solr7.1.0之solrJ的使用
- RobotFramework下的http接口自动化Set Request Header 关键字的使用
- Django(博客系统):文章内容使用django-ckeditor、文章简介使用django-tinymce
- python的join(string)函数
- React文档(二十二)context
- 关于always块内for循环的执行方式
- stl string的erase方法
- Python学习之路基础篇--02Python基础+小作业
- ";美女相册";的 js 实现代码
- Web Services的学习一
- JAVA 线程池入门事例
- 关于RSA加密算法的工具类
- Simple2D-17(音乐播放器)嵌入 ImGui 库
- u3d change terrain textrue&;height
热门文章
- 关于Membership和身份认证的记录
- easyui combobox的增加全选解决方案
- 怎么不让别人ping服务器
- 【sqli-labs】 less8 GET - Blind - Boolian Based - Single Quotes (基于布尔的单引号GET盲注)
- Type class-Typeclass-泛型基础上的二次抽象---随意多态
- 微信小程序中的iPhone X适配问题
- 浏览器内置的base64方法
- Spark中Task,Partition,RDD、节点数、Executor数、core数目的关系和Application,Driver,Job,Task,Stage理解
- select和epoll最大的区别
- Idea中修改servlet模板