01.
<%@Language=
"VBScript"
%>
02.
<%
Option
Explicit%>
03.
<%Response.Buffer =
True
%>
04.
<%
05.
On
Error
Resume
Next
06.
Dim
strPath
07.
strPath =
"test.exe"
08.
09.
If
strPath =
""
Then
10.
Response.Clear
11.
Response.Write(
"No file specified."
)
12.
Response.
End
13.
ElseIf
InStr(strPath,
".."
) > 0
Then
14.
Response.Clear
15.
Response.Write(
"Illegal folder location."
)
16.
Response.
End
17.
ElseIf
Len(strPath) > 1024
Then
18.
Response.Clear
19.
Response.Write(
"Folder path too long."
)
20.
Response.
End
21.
Else
22.
Call
DownloadFile(strPath)
23.
End
If
24.
25.
Private
Sub
DownloadFile(file)
26.
27.
Dim
strAbsFile
28.
Dim
strFileExtension
29.
Dim
objFSO
30.
Dim
objFile
31.
Dim
objStream
32.
33.
strAbsFile = Server.MapPath(file)
34.
35.
Set
objFSO = Server.CreateObject(
"Scripting.FileSystemObject"
)
36.
37.
If
objFSO.FileExists(strAbsFile)
Then
38.
Set
objFile = objFSO.GetFile(strAbsFile)
39.
40.
Response.Clear
41.
42.
43.
Response.AddHeader
"Content-Disposition"
,
"attachment; filename="
& objFile.Name
44.
Response.AddHeader
"Content-Length"
, objFile.Size
45.
Response.ContentType =
"application/octet-stream"
46.
Set
objStream = Server.CreateObject(
"ADODB.Stream"
)
47.
objStream.Open
48.
49.
objStream.Type = 1
50.
Response.CharSet =
"UTF-8"
51.
52.
objStream.LoadFromFile(strAbsFile)
53.
54.
Response.BinaryWrite(objStream.Read)
55.
objStream.Close
56.
Set
objStream =
Nothing
57.
Set
objFile =
Nothing
58.
Else
59.
Response.Clear
60.
Response.Write(
"No such file exists."
)
61.
End
If
62.
Set
objFSO =
Nothing
63.
End
Sub
64.
%>