Browser | download | browser | download <%
Dim Stream
Dim Contents
Dim FileName
Dim Fileext
Const adTypeBinary = 1
filename = request.querystring ("filename")
If FileName = "" Then
Response.Write "Invalid filename."
Response.End
End If
' Below is a file that you don't want to download
Fileext = Mid (filename, InStrRev (filename, ".") + 1)
Select case UCase (Fileext)
Case "ASP", "ASA", "ASPX", "ASAX", "MDB"
Response.Write "protected file, cannot download."
Response.End
End Select
' Download this file
Response.Clear
Response.ContentType = "Application/octet-stream"
Response.AddHeader "Content-disposition", "attachment"; Filename= "& FileName
Set Stream = server. CreateObject ("ADODB.") Stream ")
Stream.type = adTypeBinary
Stream.open
Stream.loadfromfile Server.MapPath (FileName)
While not Stream.eos
Response.BinaryWrite Stream.read (1024 * 64)
Wend
Stream.Close
Set Stream = Nothing
Response.Flush
Response.End
%>
Use: Download.asp? Filename=/files/my.doc
Put your doc file in the root directory files and you can put it somewhere else.
Such as:
<a href= "download.asp? Filename=/files/my.doc "> Click to download Word document </A>