简体   繁体   中英

Android browser rejects content-disposition:inline?

I am having trouble sending pdf files to an Android browser from a php script. Specifically, at http://aim.shef.ac.uk/misc/a.php I have the following script:

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. 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). 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. 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. However, this seems kludgy and I do not know whether it is appropriate for all Android devices.

Any suggestions?

Android phones can not render PDFs in the web browser. There is no support for that. Instead, you could use the google viewer. Have a look at https://docs.google.com/viewer for instructions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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