Is it possible to download a file from my server directly to a user’s hard drive? when I try to download a CSS file, my browser just opens the css file in a new browser (almost like Microsoft Word would). I want the user to have the actual css file though.
Code
<a href="Stylesheets/custom.css" rel="external">Download This File</a>
If you want to force a download prompt, the simplest way to do it is to use some kind of server-side scripting language to modify the headers so they include
Content-Disposition: attachment; filename="file.ext". This is very easy in PHP, but it really depends on what languages/facilities your server has available.There are things you can do to the server configuration itself to force this as well – how you do it depends on the server you are running.
If you wanted to do it in PHP, here is a short example:
getcss.php (placed in the same directory as the HTML file with the link in it)
Then your link would be: