How can I link a pdf file on my web site only downloadable, and not display this PDF in the browser?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The behavior of what to do with the content of an HTTP response is ultimately determined by the browser, not by the server. However, you can “suggest” to the browser that the content of the response is meant to be a “file” and suggest a name by which to save that file by using the content-disposition header.
Note that the HTTP protocol doesn’t really transfer “files” in the sense in which most people infer. It transfers content with associated headers. So everything you do is done through those headers which accompany the content.
Edit: I just noticed your tags… Are you talking about serving the file for download or about linking to a file served elsewhere? If the latter then I’m pretty sure it’s out of your control. Your JavaScript can maybe control the content of the request header, but the response header is entirely up to the server.