日期:2010-04-17 10:14:00 来源:本站整理
<b>ASP编程实现文件直接下载</b>[网站编程]
本文“<b>ASP编程实现文件直接下载</b>[网站编程]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
在IE举行文档链接时,假如碰到OLE支持的文档,IE会自动调用呼应程式翻开它,有时刻这种功效并非我们所需的,固然我们可以提醒用户用鼠标右键-->"目标另存为...."号令来下载文档,但这样毕竟不太友好,本文描写了操纵FSO及Streammethod显现IE直接下载文档.
- <%@ language=vbsCript Codepage=65001%>
- <%
- 'Filename must be input
- if Request("Filename")="" then
- response.write "<h1>Error:</h1>Filename is empty!<p>"
- 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 = 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("<h1>Error:</h1>"&strFilename&" does not exists!<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>Unknown Error!<p>")
- 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
- %>
以上是“<b>ASP编程实现文件直接下载</b>[网站编程]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |
评论内容只代表网友观点,与本站立场无关!
评论摘要(共 0 条,得分 0 分,平均 0 分)
查看完整评论