ASP源码
PHP源码
.NET源码
JSP源码
在IE进行文档链接时,如果遇到OLE支持的文档,IE会自动调用相应程序打开它,有时候这种功能并不是我们所需的,虽然我们可以提醒用户用鼠标右键-->"目标另存为...."命令来下载文档,但这样毕竟不太友好,本文描述了利用FSO及Stream方法实现IE直接下载文档.
<%@ language=vbscript codepage=65001%>
<%
'Filename must be input
if Request("Filename")="" then
re***nse.write "
"
else
call downloadFile(replace(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 = se***r.MapPath(strFile)
' clear the buffer
Re***nse.Buffer = True
Re***nse.Clear
' create stream
Set s = Se***r.CreateObject("AD***.Stream")
s.***n
' Set as binary
s.***e = 1
' load in the file
on error resume next
' check the file exists
Set fso = Se***r.CreateObject("Sc***ting.FileSystemObject")
if not fs***ileExists(strFilename) then
Re***nse.Write("
")
Re***nse.End
end if
' get length of file
Set f = fs***etFile(strFilename)
intFilelength = f.***e
s.***dFromFile(strFilename)
if err then
Re***nse.Write("
")
Re***nse.End
end if
' send the headers to the users Browse
Re***nse.AddHeader "Content-Disposition","attachment; filename="&f.***e
Re***nse.AddHeader "Content-Length",intFilelength
Re***nse.CharSet = "UTF-8"
Re***nse.ContentType = "application/octet-stream"
' output the file to the browser
Re***nse.BinaryWrite s.***d
Re***nse.Flush
' tidy up
s.***se
Set s = Nothing
End Function
end if
%>