A client wants a url
to be a download link.
Use case is like so:
user gets linked to example.com/download
once there, it downloads a pdf file.
Can I do this without php ?
A client wants a url
to be a download link.
Use case is like so:
user gets linked to example.com/download
once there, it downloads a pdf file.
Can I do this without php ?
HTML5 introduced the
download
attribute.Supporting user-agents will offer to download the file
foo.png
when clicking this link:You can also specify a different default file name that should be used:
Read more at http://www.w3.org/TR/html5/links.html#downloading-resources.
Note that this only works for links. When users enter the URL directly into their browsers, this will have no effect, of course. If you want that, you need to send specific HTTP headers. See for example the question: How to force download of a file?. You don’t necessarily need a programming language like PHP for that. You can do it with, for example,
.htaccess
, too: Force File(image) Download with .htaccessYou only need a link (anchor tag). The way the link behaves on click will depend on what browser you are and what settings you have in that particular browser. Some browsers will prompt you to open or save the file, other browsers will open the PDF file on a new tab or window.
You'll also need to make sure that the path to the PDF file is correct on the
href
property of your anchor tag.Use this (HTML) not PHP:
How a file is displayed is browser specific. Some may force you to download while some directly render it on the browser.
If you want to force the browser to download the file then you can set in Header the
Content-Type : application/octet-stream
Use the full url including the pdf file like.