Is there a way to force PDF files to open in the browser when the option "Display PDF in browser" is unchecked?
I tried using the embed tag and an iframe, but it only works when that option is checked.
What can I do?
Is there a way to force PDF files to open in the browser when the option "Display PDF in browser" is unchecked?
I tried using the embed tag and an iframe, but it only works when that option is checked.
What can I do?
You can do this in the following way:
If the PDF file is inside some folder and that folder doesn't have permission to access files in that folder directly then you have to bypass some file access restrictions using
.htaccess
file setting by this way:But now allow just certain necessary files.
I have used this code and it worked perfectly.
Open downloads.php from rootfile.
Then go to line 186 and change it to the following:
Oops, there were typing errors in my previous post.
If you don't want the browser to prompt the user then use "inline" for the third string instead of "attachment". Inline works very well. The PDF display immediately without asking the user to click on Open. I've used "attachment" and this will prompt the user for Open, Save. I've tried to change the browser setting nut it doesn't prevent the prompt.
If you link to a .PDF it will open in the browser.
If the box is unchecked it should link to a .zip to force the download.
If a .zip is not an option, then use headers in PHP to force the download
The correct type is
application/pdf
for PDF, notapplication/force-download
. This looks like a hack for some legacy browsers. Always use the correct mimetype if you can.If you have control over the server code:
header("Content-Disposition", "attachment; filename=myfilename.myextension");
header("Content-Disposition", "inline; filename=myfilename.myextension");
No control over the server code:
NOTE: I prefer setting the filename on the server side as you may have more information and can use common code.
If you are using CodeIgniter.
Please set: