open PDF in browser with PHP
I am doing:
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="the.pdf"');
he开发者_如何学Goader('Content-Length: ' . filesize($file));
@readfile($file);
and it works fine. The PDF opens in the browser.
Can I do an if-then-else before? I tried and I get raw PDF
%PDF-1.2 9 0 obj << /Type/Font /Subtype/Type1 /Name/F1 /FontDescriptor 8 0
Why is the if-then-else changing the headers?
thanks.
It would be helpful if you posted exactly what is your if-then-else code. My guess is you have some whitespace output before the headers are outputted.
Make sure the code in your if-then-else block isn't causing anything to be output to the page.
Once something's been output, calls to header()
won't work anymore.
精彩评论