1

I have url to PDF file. I need to have a link on the page so that when the user clicks the link, they see the "Save As" dialog.

I found a solution using an iframe, but if the user has installed a PDF plugin, the "Save As" dialog does not show up.

Is there any other way to show the user the "Save As" dialog?

Sorry, I forgot to mention that after user will click on link, request will be sent by ajax. It will be post request for a PDF file url. In the result of this request I will know there is PDF file is located, and now I would like to show the user Save as dialog instead of opening it in browser.

5
  • 1
    Did you try the header() answer in there? Commented Dec 30, 2011 at 13:14
  • This is an exact duplicate of the question you linked to, with respect you're just not reading the answers carefully enough. Commented Dec 30, 2011 at 13:29
  • in that question what i meant, there is no any correct answer for my case. I'm thinking that .htaccess can help me. The main problem what i have now - when i'm using iframe approach the pdf file loaded into it, because i have installed pdf plugin. And is seems i have only one chance to change this situation - i need to send required headers by Apache. Commented Dec 30, 2011 at 19:43
  • @user1016265: The question's answers do directly relate to what you want to do, even if you have a PDF plug-in installed. The Content-Disposition: attachment header, whether added by Apache or PHP, tells the browser what you want it to do (show a "Save As" dialog rather than presenting the PDF inline). Whether it does it is up to the browser, but in my experience they do. Commented Dec 30, 2011 at 23:17
  • and you can congratulate me i did it. I used <FilesMatch "\.(?i:pdf)$"> ForceType application/octet-stream Header set Content-Disposition attachment </FilesMatch> in .htaccess + iframe solution and result is ok! Commented Dec 31, 2011 at 5:55

2 Answers 2

2

There is a PHP way, you need to redirect your user to a php file that will include the content and pass on some headers:

header('content-type: application/x-pdf');
header('content-disposition: attachment; filename=yourfile.pdf');
readfile('yourfile.pdf');

This should overcome most if not all weird browser initiatives. If you still get the pluggin instead of the save dialog, there isn't much more you can do IMO.

Good luck

Sign up to request clarification or add additional context in comments.

Comments

0

You don't want to send the POST via ajax. Instead, POST to the iframe as described in this answer to the question you found, and use the Content-Dispostion header to tell the browser what to do with it as described in this answer to the question you found.

(Marked this "community wiki" because the question is really just a duplicate.)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.