HELP: how to force file download instead of open it

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.
 
Joined
Oct 24, 2005
Messages
1
Reaction score
0
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!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top