302重定向 php,php – 使用302重定向的Content-Disposition

你要做的是不建议检查这个问题;

Header Location + Content Disposition

Content-Disposition Location标头

但你可以做到,为了使它工作,你必须在发送之前缓冲你的整个响应.您可以使用输出缓冲来完成此操作

否则,浏览器可能会在下载文件之前解释位置标头.这两种方式都很粗略,所以你不应该这样做.

请注意,使用内容处理强制“另存为”:附件;将确保客户端不会去任何地方/导航,所以下面的方法本身应该没问题.

在php中流式传输文件

// To use header() with 'content-type', why don't you use mime_content_type() function rather than checking the type on the basis of extension?

// Example code:

$file="test.docx";

header("Pragma: public");

header('Content-disposition: attachment; filename='.$file);

header("Content-type: ".mime_content_type($file));

header('Content-Encoding: identity');

ob_clean();

flush();

readfile($file);

?>

// Use $file to map to whichever type of file.

// Note: the mime types should already be defined in apache settings

请注意,原始答案使用的是Content-Transfer-Encoding,它实际上并不存在于HTTP中.该消息来源下面的评论解释了它:http://www.php.net/manual/en/function.header.php#107044

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值