高分解释一小段关于在线压缩文件下载的代码

allen0228 2009-03-29 07:37:33

include $abs_path.'/include/classes/class.zip.php';

$dir_array = explode(',', $_GET['namestr']);
for($i=0;$i<count($dir_array);$i++)
{
$dir_array[$i] = $abs_path.'/download/'.$dir_array[$i];
}

$filename = $abs_path.'/admin/backup/'.randompass(10).'_site_templates.zip';

$ziper = new zipfile();
$ziper->addFiles($dir_array);
$ziper->output($filename);

header("Cache-control: private");
header("Content-type: application/zip");
header("Content-transfer-encoding: binary\n");
header("Content-disposition: attachment; filename=\"".strtolower(str_replace(" ", "_", $settings[title]))."_templates.zip\"");
header("Content-Length: ".filesize($filename));
readfile($filename);
@unlink($filename);
exit;

其中 $_GET['namestr'] 获取的是多个文件的名字
$abs_path是根目录
我用迅雷就可以测试
可是直接保存 就提示无法下载
不怎么看得懂
忘高手帮忙了
还有用xunlei保存下来的是整个路径 从盘符开始 我想直接给文件打个包
...全文
144 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
Zijian_Zhang 2009-04-05
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 suiye 的回复:]
问题的描述找到了 还是manual好啊

The issue with IE downloading dynamic files produced on an SSL encrypted connection with the no-cache Cache Control settings affects most types of files, including .csv, .txt and all Office document types in addition to .pdf files.

This problem affects IE7 as well as IE6 and IE5.5. I haven't found a user using anything earlier so I cannot confirm if it is ha…
[/Quote]

呵呵,学习了,出了客户端的问题,我通常是用Firefox等监控软件看看HTTP标头和传输状态,哈哈。
ptiand 2009-04-05
  • 打赏
  • 举报
回复
学到东西了
Siramizu 2009-04-04
  • 打赏
  • 举报
回复
http://www.google.com/search?q=Pragma%3A+hack&ie=utf-8&oe=utf-8&aq=t&rls=org.mozilla:en-US:official&client=firefox

http://www.activecollab.com/forums/topic/903/

Notice the "Pragma: hack" That is necessary because PHP automatically set " Pragma: no-cache" and there is no way to override that in any of the PHP settings
allen0228 2009-04-04
  • 打赏
  • 举报
回复
问题的描述找到了 还是manual好啊

The issue with IE downloading dynamic files produced on an SSL encrypted connection with the no-cache Cache Control settings affects most types of files, including .csv, .txt and all Office document types in addition to .pdf files.

This problem affects IE7 as well as IE6 and IE5.5. I haven't found a user using anything earlier so I cannot confirm if it is happening in earlier IE browsers, though I suspect it is. As far as my users have reported, this is not an issue in FF, Opera or Safari.

There is more information on this issue at http://support.microsoft.com/kb/812935 in addition to the many other MSDN reports on this same issue.
allen0228 2009-04-04
  • 打赏
  • 举报
回复
我自己看手册 搞好了 可是我就是想不通
下面是我上次最想不同的一段code(红色部分)
header("Cache-control: private, must-revalidate");
header("Pragma: hack");
header("Content-type: application/zip");
header("Content-transfer-encoding: binary\n");
header("Content-disposition: attachment; filename=\"download.zip\"");
header("Content-Length: ".filesize($filename));

这个hack 我理解是和css中的hack是不是一个意思 可是为何这个里面要加上这个呢
还有 我有段code 没有加这个也是可以的
rex100 2009-03-31
  • 打赏
  • 举报
回复
顶3楼
程序猿之殇 2009-03-30
  • 打赏
  • 举报
回复
用迅雷下载的时候,查看一下下载的日志,看有没有转向之类的.
用ff下载,查看控制台的信息.
最好先别去掉unlink这段,查看zip的下载路径与真实文件路径是否想同,这是细活,慢慢调试吧.

//MS一个zip类
include $abs_path.'/include/classes/class.zip.php';

//获取get过来的文件名(多文件用,号隔开),将其转成数组
$dir_array = explode(',', $_GET['namestr']);
//遍历一下,构造文件真实路径
for($i=0;$i<count($dir_array);$i++)
{
$dir_array[$i] = $abs_path.'/download/'.$dir_array[$i];
}
//构造要生成的zip包
$filename = $abs_path.'/admin/backup/'.randompass(10).'_site_templates.zip';

//申明zip类
$ziper = new zipfile();
//添加实体文件
$ziper->addFiles($dir_array);
//输出到zip包里
$ziper->output($filename);

//读取zip包后,删除zip包
header("Cache-control: private");
header("Content-type: application/zip");
header("Content-transfer-encoding: binary\n");
header("Content-disposition: attachment; filename=\"".strtolower(str_replace(" ", "_", $settings[title]))."_templates.zip\"");
header("Content-Length: ".filesize($filename));
readfile($filename);
@unlink($filename);
exit;
南山谷主8 2009-03-30
  • 打赏
  • 举报
回复
帮你求救
allen0228 2009-03-29
  • 打赏
  • 举报
回复
高手急救啊

20,384

社区成员

发帖
与我相关
我的任务
社区描述
“超文本预处理器”,是在服务器端执行的脚本语言,尤其适用于Web开发并可嵌入HTML中。PHP语法利用了C、Java和Perl,该语言的主要目标是允许web开发人员快速编写动态网页。
phpphpstorm 技术论坛(原bbs)
社区管理员
  • 开源资源社区
  • phpstory
  • xuzuning
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧