<% ' ========================================= ' ' 利用ADODB.Stream使用浏览器下载服务器文件 ' download.asp?file=相对路径的文件 ' ' ========================================= file="imgbutton1.gif" call downloadFile(replace(replace(file,"\",""),"/","")) 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) Response.Buffer = True ' clear the buffer Response.Clear
Set s = Server.CreateObject("ADODB.Stream") ' create stream s.Open s.Type = 1 ' Set as binary ''on error resume next ' load in the file ' check the file exists 'Set fso = Server.CreateObject("Scripting.FileSystemObject") 'if not fso.FileExists(strFilename) then ' Response.Write("<h1>Error:</h1>" & strFilename & " does not exist<p>") ' Response.End 'end if ' get length of file 'Set f = fso.GetFile(strFilename) 'intFilelength = f.size s.LoadFromFile(strFilename) 'if err then ' Response.Write("<h1>Error: </h1>" & err.Description & "<p>") ' Response.End 'end if ' send the headers to the users browser '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
Response.Buffer = True ' clear the buffer
Response.Clear
s="aa.txt"
download ssub download(f)
set objdownload = server.createobject("adodb.stream")
objdownload.Open
objdownload.Type = 1
f=server.mappath(f)
objdownload.LoadFromFile f
Response.BinaryWrite objdownload.Read
end sub
%>
如果是未知的 ,就可以直接下载了.有ASP可以实现..
直接让客户端浏览器下载已知类型的文件
http://www.csdn.net/Develop/Read_Article.asp?Id=13004
' =========================================
'
' 利用ADODB.Stream使用浏览器下载服务器文件
' download.asp?file=相对路径的文件
'
' =========================================
file="imgbutton1.gif"
call downloadFile(replace(replace(file,"\",""),"/","")) 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) Response.Buffer = True ' clear the buffer
Response.Clear
Set s = Server.CreateObject("ADODB.Stream") ' create stream
s.Open
s.Type = 1 ' Set as binary
''on error resume next ' load in the file
' check the file exists
'Set fso = Server.CreateObject("Scripting.FileSystemObject")
'if not fso.FileExists(strFilename) then
' Response.Write("<h1>Error:</h1>" & strFilename & " does not exist<p>")
' Response.End
'end if ' get length of file
'Set f = fso.GetFile(strFilename)
'intFilelength = f.size s.LoadFromFile(strFilename)
'if err then
' Response.Write("<h1>Error: </h1>" & err.Description & "<p>")
' Response.End
'end if ' send the headers to the users browser
'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
%>
有没有类似saveas之类的函数可以用啊,实际上点目标另存为就可以下载,但是我想做一个下载按纽来实现,主要是单位上很多人计算机极不熟悉,要做一个直观的
就可以直接下载啦.