标题位置 + 内容配置

Header Location + Content Disposition(标题位置 + 内容配置)
本文介绍了标题位置 + 内容配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个下载页面,你点击一个链接,它会打开/downloads/download/randomhash

So I have a downloads page where you click a link, it opens /downloads/download/randomhash

在数据库中找到随机哈希,我增加一个下载计数器,然后重定向到实际文件,例如/uploads/2012/file.png.

randomhash is found in the db, i increment a download counter, and then redirect to the actual file e.g. /uploads/2012/file.png.

一切正常,除了重定向做我想做的事.我不确定为什么它不起作用...

Everything works except for the redirect doing what I'd like it to do. I'm not sure why it's not working...

  header("Location: " . $row->uri);
  header("Content-Disposition: attachment; filename=$row->name");

在第一次加载文件时,它具有适当的 content-disposition 标头(在 firebug 中),但它不会提示下载文件(它应该下载,对吗??).有什么想法吗?

On the first load of the file, it has the appropriate content-disposition header (in firebug), but it doesn't prompt the file to be downloaded (which it should, right??). Any ideas?

响应标头:

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 标头,告诉浏览器重定向到哪里.我的建议是只在响应中流式传输附件,没有重定向

You are setting the Content-Disposition header in the same response which tells the browser where to redirect. My suggestion is to just stream the attachment on the response, with no redirect

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);

这篇关于标题位置 + 内容配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)