小编典典

正确的pdf文件的PHP标头下载

php

当用户单击链接时,我真的很难让我的应用程序打开pdf。

到目前为止,anchor标签重定向到一个页面,该页面发送的标头为:

$filename='./pdf/jobs/pdffile.pdf;

$url_download = BASE_URL . RELATIVE_PATH . $filename;


header("Content-type:application/pdf");



header("Content-Disposition:inline;filename='$filename");

readfile("downloaded.pdf");

这似乎不起作用,过去有人成功解决过此问题吗?


阅读 494

收藏
2020-05-26

共1个答案

小编典典

w3schools上的示例2 显示了您要实现的目标。

<?php
header("Content-type:application/pdf");

// It will be called downloaded.pdf
header("Content-Disposition:attachment;filename='downloaded.pdf'");

// The PDF source is in original.pdf
readfile("original.pdf");
?>

还请记住,

重要的是要注意必须在发送任何实际输出之前调用header()(在PHP 4和更高版本中,可以使用输出缓冲来解决此问题)

2020-05-26