Php 内容类型导致chrome调用函数两次
下面代码中最奇怪的问题。它将pdf报告返回到浏览器Php 内容类型导致chrome调用函数两次,php,google-chrome,pdf,content-type,Php,Google Chrome,Pdf,Content Type,下面代码中最奇怪的问题。它将pdf报告返回到浏览器 function cart_aspdf() { trace('cart_aspdf_in'); $file = 'order_WS000250.pdf'; header('Content-type: application/pdf'); header('Content-Disposition: inline; filename="' . $file . '"'); $file = APPPATH.'pd
function cart_aspdf() {
trace('cart_aspdf_in');
$file = 'order_WS000250.pdf';
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="' . $file . '"');
$file = APPPATH.'pdfcache/'.$file;
header('Content-Transfer-Encoding: binary');
header('Content-Length: ' . filesize($file));
header('Accept-Ranges: bytes');
trace('cart_aspdf_readfile');
@readfile($file);
trace('cart_aspdf_out');
}
opera、firefox、ie、safari中的跟踪输出与您预期的一样:
如果我省略了内容类型行,但chrome显示了没有用的原始pdf数据,则不会出现问题我遇到了相同的问题
header('Content-Disposition: inline;');
无论出于何种原因,当内容配置内联时,它会调用页面两次
这让我在尝试使用推荐人时遇到了问题,因为第二次呼叫没有传递推荐人数据
使用
header('Content-Disposition: attachment;');
只运行一次,但不会显示在浏览器PDF查看器中。它将下载该文件
我认为这需要发布在chrome的bugtracker上。这很烦人,对于流式文件来说是带宽浪费。Chrome无法调用您的函数,但Chrome可以重新加载调用该函数的页面。为防止代码多次调用函数,请添加exit;嗨,安德烈,在读取文件后退出(我想这就是你的意思)没有什么区别。该函数是通过网页ie等上的锚来调用的。或者,我可以只输入url,每次按rfresh时,我都可以看到跟踪。它在除chrome之外的所有浏览器中都能完美工作。我想停止它,因为目前,代码只输出一个完成的pdf,但意图是pdf将在运行中生成,如果chrome将导致生成两次,这是一个非运行程序。比尔