php – 标题位置内容处理
发布时间:2020-12-13 17:10:59 所属栏目:PHP教程 来源:网络整理
导读:所以我有一个下载页面,你点击一个链接,它打开/下载/下载/ randomhash 在数据库中找到randomhash,我增加一个下载计数器,然后重定向到实际文件,例如/uploads/2012/file.png. 一切都有效,除了重定向做我想做的事情.我不确定为什么它不起作用…… header("Locati
所以我有一个下载页面,你点击一个链接,它打开/下载/下载/ randomhash
在数据库中找到randomhash,我增加一个下载计数器,然后重定向到实际文件,例如/uploads/2012/file.png. 一切都有效,除了重定向做我想做的事情.我不确定为什么它不起作用…… header("Location: " . $row->uri); header("Content-Disposition: attachment; filename=$row->name"); 在第一次加载文件时,它具有相应的内容处置标头(在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标头,该响应告诉浏览器重定向的位置.我的建议是仅在响应中流式传输附件,而不进行重定向
header('Content-Disposition: attachment; filename=file-to-be-downloaded.jpg'); header('Content-type: image/jpeg'); // or what is relevant,ie application/octet-stream $fn=fopen("path-to-file/file-to-be-downloaded.jpg","r"); fpassthru($fn); (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |