Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用PHP在浏览器中打开PDF_Php_Html_Pdf - Fatal编程技术网

用PHP在浏览器中打开PDF

用PHP在浏览器中打开PDF,php,html,pdf,Php,Html,Pdf,我正在做: header('Content-type: application/pdf'); header('Content-Disposition: inline; filename="the.pdf"'); header('Content-Length: ' . filesize($file)); @readfile($file); 而且效果很好。PDF将在浏览器中打开 我可以先做一个if-then-else吗?我试过了,我得到了原始PDF %PDF-1.2 9 0 obj <<

我正在做:

header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="the.pdf"');
header('Content-Length: ' . filesize($file));
@readfile($file);
而且效果很好。PDF将在浏览器中打开

我可以先做一个if-then-else吗?我试过了,我得到了原始PDF

%PDF-1.2 9 0 obj << /Type/Font /Subtype/Type1 /Name/F1 /FontDescriptor 8 0

%PDF-1.2 9 0 obj确保if-then-else块中的代码不会导致任何内容输出到页面


一旦输出了某些内容,对
header()
的调用将不再起作用。

如果您准确地发布了if-then-else代码,这将非常有用。我猜在输出标题之前,您会有一些空白输出。

您能给出一些示例代码吗?您是对的。前空格