1

I want people to be able to click my link and download my file. But when I link to the file download on my site, it just brings them to the code for the file. I am trying to upload a .cpp file (c plus plus). It's in my downloads folder but when I link to there it displays the .cpp file rather than download it.

Any help is appreciated.

RJFalconer
  • 10,890
  • 5
  • 51
  • 66
Crju
  • 101
  • 1
  • 2
  • 6
  • 2
    Your title does not seem to agree with your question text. Do you want a user in the browser to download a file, rather than have the browser render it? – bitfiddler Jul 02 '13 at 01:29
  • (Updated title/description based on Syd's comments to answers) – RJFalconer Oct 16 '13 at 13:38

3 Answers3

1

You can set the Content-Disposition header to "attachment" in your HTTP response. If you let me know what server platform, I'll try to give more detail.

bitfiddler
  • 2,095
  • 1
  • 12
  • 11
  • (Sorry I'm really nooby with web development) here's what I am trying to do. www.zuhon.com/opentextengine on there, I want you to be able to click on the v.2 and download the file, rather than going to the location and seeing the source for it... – Crju Jul 02 '13 at 01:34
  • Yes, Content-Disposition is the way. You will have to direct the link to a script on your server that returns the file with header set. Take a look at http://stackoverflow.com/questions/8875949/how-to-implement-content-disposition-attachment [link](http://stackoverflow.com/questions/8875949/how-to-implement-content-disposition-attachment) if you are using PHP on that host. – bitfiddler Jul 02 '13 at 01:39
1

You will have to write some code to set the HTTP response header ContentType to "application/x-force-download". This tells the browser what you really want is a file download, instead of the default action (file open). You will also need to set the ContentLength header. This allows the browser to display a progress bar.

If you use ASP.NET, there are some commercial product for this purpose:

http://www.essentialobjects.com/Products/EOWeb/Downloader.aspx

It basically does what stated above with a few extra features.

user2540812
  • 212
  • 2
  • 2
0

That's because the browser knows how to read the file - you could ask users on the page to right click on the link and click "Save Target As" rather than just having a link.

Herp
  • 263
  • 1
  • 3
  • 13