PDF redirection shows blank on Chrome
I'm having this issue that I can't solve for the life of me.
I have a simple php script that redirects to pdfs, the code is as follows:
$file = "url/to/file";
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private", false);
header("Content-Description: File Transfer");
header('Content-type: application/pdf');
header('Content-Disposition: inline; filename="somefile.pdf"');
header('Content-Transfer-Encoding: binary');
readfile($file);
exit();
If I try it directly in a browser tab, it works, it connects with Chrome's pdf plugin and shows it to me. If I try to put this on a link on another page, or try to open it via window.open in javascript, It shows a blank page. This only happens in Chrome and Safari, Firefox and Edge show it fine. Before anyone asks, I've tried it with and without the cache and content-description headers, which I've got from answers I found here, this is just the last version I have.
Any ideas?
Thanks in advance
EDIT
I forgot to mention that the problem persists on the blank tab even if I reload the page. I've checked the Network tab on devtools, they show identical results for bot requests and responses (the redirect and the direct one) but the redirect doesn't work. Also, no errors of any kind on either one.
Also, I've tried it without the exit(), doesn't change a thing.
As mentioned in the comments by ylva, for anyone searching for this, the answer can be found here
Open PDF from Chrome IFRAME failed with default PDF viewer
Main thing is, Chrome's PDF viewer embeds the PDF as an application, so if the link to a PDF file comes from an iframe, and this iframe has the sandbox attribute, chrome won't let it run, you either have to remove the sandbox attribute or have to install your own PDF viewer. So it had nothing to do with the PHP code itself.
Cheers
链接地址: http://www.djcxy.com/p/36436.html上一篇: 是否可以将字节[]数组写入C#文件中?
下一篇: 在Chrome上PDF重定向显示空白