简体   繁体   English

客户端缺少内容处理标头

[英]Content-Disposition header missing at client

I have a php add which calls LaTeX then passes the PDF to the browser. 我有一个php add,它调用LaTeX然后将PDF传递到浏览器。 Since my users will be paying for this service, I want to make sure they are given the option to save the PDF rather than hitting my server again and again. 由于我的用户将为此服务付费,因此我想确保为他们提供了保存PDF的选项,而不是一再打我的服务器。

exec("cd tex && latex {$_SESSION['sen_id']}.tex && pdflatex {$_SESSION['sen_id']}.tex", $output);
$pdf = substr($file,0,-3).'pdf';
if (file_exists($pdf)) {
  //header('Content-Description: File Transfer');
  header('Content-Type: application/pdf');
  //header('Content-Length: ' . filesize($pdf));
  header('Content-Disposition: attachment;filename='.date('Ymd-His').'-'.basename($pdf));
  header('Content-Transfer-Encoding: binary');
  header('Expires: 0');
  header('Cache-Control: no-cache');
  header('Pragma: no-cache');
  ob_clean();
  flush();
  readfile($pdf);
  exit;
} else {
  echo '<h1>No PDF Produced</h1>';
  echo nl2br(print_r($output,true));
}

Using Wireshark, I have noticed that the Content-Disposition header is either not set or doesn't reach the client. 使用Wireshark,我注意到Content-Disposition标头未设置或未到达客户端。

HTTP/1.1 200 OK\r\n
Date: Tue, 22 Jun 2010 14:15:10 GMT\r\n
Server: Apache/2.0.55 (Ubuntu) mod_jk/1.2.14 mod_python/3.1.4 Python/2.4.3 PHP/5.1.2 mod_ssl/2.0.55 OpenSSL/0.9.8a mod_perl/2.0.2 Perl/v5.8.7\r\n
X-Powered-By: PHP/5.1.2\r\n
Set-Cookie: SESS0d6c65b0599f5b70f6bbc50cfc5b2f94=2b23ba1f74f5f1f641365e9fbb45870d; expires=Thu, 15 Jul 2010 17:48:30 GMT; path=/; domain=.<domain removed>\r\n
Content-Transfer-Encoding: binary\r\n
Expires: 0\r\n
Cache-Control: no-cache\r\n
Pragma: no-cache\r\n
Connection: close\r\n
Transfer-Encoding: chunked\r\n
Content-Type: application/pdf\r\n
\r\n

So far, the tips I've found say "use octet-steam", "don't use octet-stream", "put spaces after the colons", "Capitalise each word" and "wrap the filename in quotes". 到目前为止,我发现的技巧是“使用八位字节流”,“不要使用八位字节流”,“在冒号后放置空格”,“将每个单词大写”和“将文件名括在引号中”。 I guess there's a lot of misinformation put out by people who got lucky. 我想幸运的人会散布很多错误的信息。

I don't know why the header's being stripped, but this page describes how you can encode the file name in the content disposition header and its implications for browser interoperability. 我不知道为什么要删除标题,但是此页面介绍了如何在内容处置标题中编码文件名及其对浏览器互操作性的影响。

In these cases, I settled for the solution I wrote in the PHP manual page here (see the first example). 在这些情况下,我选择了在此处的PHP手册页中编写的解决方案(请参阅第一个示例)。

In your case , you're using an invalid header, which, however, should work with all the major browsers. 您的情况下 ,您使用的是无效的标头,但是该标头应可在所有主要的浏览器上使用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM