简体   繁体   English

Android浏览器拒绝内容处理:内联?

[英]Android browser rejects content-disposition:inline?

I am having trouble sending pdf files to an Android browser from a php script. 我无法从php脚本将PDF文件发送到Android浏览器。 Specifically, at http://aim.shef.ac.uk/misc/a.php I have the following script: 具体来说,在http://aim.shef.ac.uk/misc/a.php我有以下脚本:

header('Content-Type: application/pdf');
header("Content-Disposition:inline;filename=\"c.pdf\"");
readfile('c.pdf');

This works as expected in a variety of desktop browsers, and also with an iPhone: the pdf file is displayed in the browser window, just as if I had browsed to http://aim.shef.ac.uk/misc/c.pdf directly. 这可以在各种桌面浏览器中使用,也可以在iPhone上使用:pdf文件显示在浏览器窗口中,就像我浏览过http://aim.shef.ac.uk/misc/c一样。 pdf直接。 However, when I try it in an Android (2.3.3) phone, essentially nothing happens (despite the fact that the phone has several apps that can display pdf files). 但是,当我在Android(2.3.3)手机中试用它时,基本上没有任何反应(尽管手机有几个可以显示pdf文件的应用程序)。 If I visit c.pdf directly, or if I change 'inline' to 'attachment' then the phone offers to save the file and then I can view it. 如果我直接访问c.pdf,或者我将'inline'更改为'attachment',那么手机会提供保存文件然后我可以查看它。 This is less convenient, so I don't want to use 'attachment' for clients that can deal properly with 'inline'. 这样不太方便,所以我不想对能够正确处理'内联'的客户使用'附件'。 I could just test $_SERVER['HTTP_USER_AGENT'] for the substring 'Android', and set the content disposition based on that. 我可以为子串'Android'测试$ _SERVER ['HTTP_USER_AGENT'],并根据它设置内容处理。 However, this seems kludgy and I do not know whether it is appropriate for all Android devices. 但是,这似乎很糟糕,我不知道它是否适合所有Android设备。

Any suggestions? 有什么建议?

Android phones can not render PDFs in the web browser. Android手机无法在网络浏览器中呈现PDF。 There is no support for that. 没有支持。 Instead, you could use the google viewer. 相反,您可以使用谷歌浏览器。 Have a look at https://docs.google.com/viewer for instructions. 有关说明,请访问https://docs.google.com/viewer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM