<%
Response.ContentType = "application/octet-stream"
Response.AddHeader "Content-Disposition","attachment; filename=xxx.pdf"
response.binarywrite getBinaryFile(Server.MapPath("xxx.pdf"))
function getBinaryFile(fileSpec)
Dim adTypeBinary
adTypeBinary = 1
Dim oStream
set oStream = server.createobject("ADODB.Stream")
oStream.Open
oStream.Type = adTypeBinary
oStream.LoadFromFile fileSpec
getBinaryFile= oStream.read
set oStream=nothing
end function
%>
dim StrFile,StrFilename
dim IntFilelength
dim Range,length
dim s,f
dim ErrNo,ErrDes
StrFile=request.QueryString.Item("filename")
if StrFile = "" then
response.Redirect "message.asp?ErrNo=3"
else
StrFilename = server.MapPath(StrFile)
if instr(StrFilename,"\temp\") then
else
response.Redirect "message.asp?ErrNo=0&ErrDes=" & StrFile
end if
'Response.Buffer = True
'Response.Clear
Set s = Server.CreateObject("ADODB.Stream")
s.Type = 1
s.Mode=3
s.Open
on error resume next
Set fso = Server.CreateObject("Scripting.FileSystemObject")
if not fso.FileExists(strFilename) then
set fso=nothing
s.close
set s= nothing
response.Redirect "message.asp?ErrNo=0"
end if
Set f = fso.GetFile(strFilename)
IntFilelength = f.size
s.LoadFromFile(strFilename)
if err then
set fso=nothing
s.close
set s= nothing
set f=nothing
ErrNo = Err.Number
ErrDes = Err.Description
response.Redirect "message.asp?ErrNo=" & ErrNo & "&ErrDes=Download<br/>" & ErrDes
end if
Response.ContentType = "application/octet-stream"
Response.AddHeader "Content-Disposition", "attachment; filename=" &f.name
Response.CharSet = "UTF-8"
Range=Mid(Request.ServerVariables("HTTP_RANGE"),7)
if Range<>"" then
length=Clng(Split(Range,"-")(0))
intFilelength=intFilelength-length
s.position=length
end if
Response.AddHeader "Content-Length", intFilelength
Response.BinaryWrite s.Read
'Response.Flush
s.Close
set fso=nothing
set f=nothing
Set s = Nothing