HELP: how to force file download instead of open it

  • Thread starter Thread starter kana
  • Start date Start date
K

kana

I have been trying to modify mime.types and httpd.conf
files,
so some files, such as .xls, or .txt can be downloaded
instead of viewed by browser automatically.

however, it only works for netscape, the IE will anyway
open the file (except .zip or .exe)

is there anyone knows how to make a cgi program
so I can force file download instead of open it when
user left click a link on the web page (not right click
"then choose 'save target as').

thank you in advance.
 
I use this:

change you links to: download.asp

in download.asp paste this:

<%
Response.ContentType = "application/x-unknown" ' arbitrary
fn = Request.querystring("file")
FPath = "../files/" & fn
Response.AddHeader "Content-Disposition","attachment; filename=" & fn
Set adoStream = CreateObject("ADODB.Stream")
adoStream.Open()
adoStream.Type = 1
adoStream.LoadFromFile(FPath)
Response.BinaryWrite adoStream.Read()
adoStream.Close
Set adoStream = Nothing
Response.End
%>

Change FPath to your folder path where resides your files.

your links must have to be:

download.asp?file=___________


_________ = your filename.


Hoope this be useful for you, any comment:
(e-mail address removed)


See ya!
 
Back
Top