【发布时间】:2012-03-16 13:29:23
【问题描述】:
所以我有一个下载页面,你点击一个链接,它会打开 /downloads/download/randomhash
在数据库中找到随机哈希,我增加一个下载计数器,然后重定向到实际文件,例如/uploads/2012/file.png.
一切正常,除了重定向做我想做的事。我不确定为什么它不起作用...
header("Location: " . $row->uri);
header("Content-Disposition: attachment; filename=$row->name");
在第一次加载文件时,它具有适当的 content-disposition 标头(在 firebug 中),但它不会提示下载文件(它应该下载,对吗??)。有什么想法吗?
响应标头:
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0, public
Connection: Keep-Alive
Content-Disposition: attachment; filename=promotion_photo_2.jpg
Content-Encoding: gzip
Content-Length: 20
Content-Type: text/html; charset=utf-8
Date: Mon, 27 Feb 2012 01:01:22 GMT
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Keep-Alive: timeout=5, max=100
Location: /uploads/2012/mediakitD3CF.jpg
Pragma: no-cache
Server: *
Vary: Accept-Encoding
X-Powered-By: *
X-UA-Compatible: IE=Edge,chrome=1
【问题讨论】:
-
您应该重定向到将处理适当标头的下载控制器,目前您只需将 Content-Disposition 标头添加到重定向标头
标签: php http-headers content-disposition