2010-06-22 160 views
1

我有一个php add,它调用LaTeX然后将PDF传递给浏览器。由于我的用户将为此服务付费,我想确保他们可以选择保存PDF,而不是一次又一次地打开我的服务器。在客户端缺少Content-Disposition头文件

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

使用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 

到目前为止,我已经找到了提示说“使用八位蒸”,“不使用八位字节流”,“把空格冒号后”,“为每个字”和“包装文件名用引号“。我想有很多幸运的人发布的错误信息。

回答

1

我不知道为什么标题被剥离,但this page描述了如何编码内容处置标题中的文件名及其对浏览器互操作性的影响。

在这些情况下,我选择了我在PHP手册页here(参见第一个示例)中编写的解决方案。

your case中,您使用的标题无效,但应与所有主流浏览器配合使用。