<% @ Language = VBScript codePage = 65001%>
<%
'Filename must be input
If request ("FILENAME") = "" then
Response. Write "Else
Call downloadfile (replace (Request ("FILENAME "),"\",""),"/",""))
Function downloadfile (strfile)
'Make sure you are on the latest MDAC version for this to work
'Get full path of specified file
Strfilename = server. mappath (strfile)
'Clear the buffer
Response. Buffer = true
Response. Clear
'Create stream
Set S = server. Createobject ("ADODB. Stream ")
S. Open
'Set as binary
S. type = 1
'Load in the file
On Error resume next
'Check the file exists
Set FSO = server. Createobject ("scripting. FileSystemObject ")
If not FSO. fileexists (strfilename) then
Response. Write ("Response. End
End if
'Get length of File
Set F = FSO. GetFile (strfilename)
Intfilelength = f. Size
S. loadfromfile (strfilename)
If err then
response. Write ("
error:
unknown error!
")
response. end
end if
'send the headers to the users browse
response. addheader "content-disposition", "attachment; filename =" & F. name
response. addheader "Content-Length", intfilelength
response. charset = "UTF-8"
response. contenttype = "application/octet-stream"
'output the file to the browser
response. binarywrite S. read
response. flush
'tidy up
S. close
set S = nothing
end function
end if
%>