Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Force a file download in HTML

 
Chethan Kumar Baliga
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am looking for a file download feature.
I have implemented the same using "href"
Ex: -
<a href="http://servername ort/folder/file.txt"> Download text file</a>
On click of this link however, the file directly opens in the browser window instead of being downloaded. Right-clicking on the link and selecting "Save Target As" is one option to download it.
What I am looking for is, ceratin file types (viz. zip, tif etc.) promptly show the "File Download" dialog box, others (viz. txt, html etc.) directly open in the browser window.
This is because of the "Content-type". There is some tag (meta or something else) where one can specify the "Content-type" OR "Content-disposition" so that the user is forced to download the file, no matter what (File Download should appear!!!). Does anyone have the exact code for this in simple HTML???
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm wondering if the 'a href' supports the 'type' attribute that exists in other tags...
<a href="..." type="application/unknown">... etc
Might be worth a try.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"Technical_User",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at http://www.javaranch.com/name.jsp.
We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please edit your profile and select a new name which meets the requirements.
Thanks.
Dave
 
Randall Twede
Ranch Hand
Posts: 4481
3
Java Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if David's suggestion doesnt work, i would just compress(zip) any file you want to send rather than display
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic