我正在检查用raw php编写的应用程序,没有任何框架。在一个模块中,有报告使用FPDF生成并且工作正常,除了pdf被缓存。在生成过程的初始调用是如何使FPDF生成的pdf不可缓存?
<a href="tr_inci_print.php" target="_new">Print</a>
tr_inci_print.php使用2个参数,年份和月份中存储的会话。我已将代码更改为
<a href="tr_inci_print.php?anio=<?php echo $anio; ?>&mes=<?php echo $mes; ?>" target="_new">Imprimir</a>
由于每个月都会更改URI,因此部分解决了问题。但是,如果数据在外部发生变化并且浏览器仍在原始页面中,则重新链接链接确实会生成未更新的pdf。
有什么办法可以改变$ FPDF-> output()来使pdf不可缓存?
------部分解决-------------------
以下oezi答案,改:
$oPdf->output()
与
$buffer=$oPdf->Output('','S');
header('Content-Type: application/pdf');
header('Content-Length: '.strlen($buffer));
header('Content-Disposition: inline; filename="doc.pdf"');
header("Cache-Control: no-cache, must-revalidate, max-age=1"); // HTTP/1.1
header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); // any date in the past
header('Pragma: public');
ini_set('zlib.output_compression','0');
echo $buffer;
上解决了在Chrome和IE浏览器的问题,但不能在Firefox 4
谢谢oezi,但没有工作。我在output()之前插入代码,但它没有效果,仍然获得缓存版本。 – 2011-03-28 10:49:47
不好意思。它在Chrome中运行,在FF4中失败。 – 2011-03-28 11:00:45
from output()函数:\t header('Cache-Control:private,max-age = 0,must-revalidate');所以它重写了指令。将尝试做我自己的输出。 – 2011-03-28 11:07:51