上一篇:一个18位身份证校验计算函数 >>
利用Adodb.Stream直接下载文件
1、设置你的服务器的iis,给doc等后缀名做映射
2、在向客户端发送时设置其contenttype
下面详细说明方法2
程序代码:
| _code style="display: none" name="html_code"><% response.buffer = true response.clear dim url dim fso,fl,flsize dim dname dim objstream,contenttype,flname,isre,url1 *********************************************调用时传入的下载文件名 dname=trim(request("n")) ****************************************************************** if dname<>"" then ******************************下载文件存放的服务端目录 url=server.mappath("/")&"\"&dname *************************************************** end if set fso=server.createobject("scripting.filesystemobject") set fl=fso.getfile(url) flsize=fl.size flname=fl.name set fl=nothing set fso=nothing %> <% set objstream = server.createobject("adodb.stream") objstream.open objstream.type = 1 objstream.loadfromfile url select case lcase(right(flname, 4)) case ".asf" contenttype = "video/x-ms-asf" case ".avi" contenttype = "video/avi" case ".doc" contenttype = "application/msword" case ".zip" contenttype = "application/zip" case ".xls" contenttype = "application/vnd.ms-excel" case ".gif" contenttype = "image/gif" case ".jpg", "jpeg" contenttype = "image/jpeg" case ".wav" contenttype = "audio/wav" case ".mp3" contenttype = "audio/mpeg3" case ".mpg", "mpeg" contenttype = "video/mpeg" case ".rtf" contenttype = "application/rtf" case ".htm", "html" contenttype = "text/html" case ".txt" contenttype = "text/plain" case else contenttype = "application/octet-stream" end select response.addheader "content-disposition", "attachment; filename=" & flname response.addheader "content-length", flsize response.charset = "utf-8" response.contenttype = contenttype response.binarywrite objstream.read response.flush response.clear() objstream.close set objstream = nothing %> _lightcode style="border-right: #999999 1px dotted; padding-right: 5px; border-top: #999999 1px dotted; padding-left: 5px; font-size: 11px; padding-bottom: 5px; border-left: #999999 1px dotted; padding-top: 5px; border-bottom: #999999 1px dotted; font-family: sans-serif; height: 40px; background-color: #f9f9f9" name="html_lightcode"><% response.buffer = true response.clear dim url dim fso,fl,flsize dim dname dim objstream,contenttype,flname,isre,url1 *********************************************调用时传入的下载文件名 dname=trim(request("n")) ****************************************************************** if dname<>"" then ******************************下载文件存放的服务端目录 url=server.mappath("/")&"\"&dname *************************************************** end if set fso=server.createobject("scripting.filesystemobject") set fl=fso.getfile(url) flsize=fl.size flname=fl.name set fl=nothing set fso=nothing %> <% set objstream = server.createobject("adodb.stream") objstream.open objstream.type = 1 objstream.loadfromfile url select case lcase(right(flname, 4)) case ".asf" contenttype = "video/x-ms-asf" case ".avi" contenttype = "video/avi" case ".doc" contenttype = "application/msword" case ".zip" contenttype = "application/zip" case ".xls" contenttype = "application/vnd.ms-excel" case ".gif" contenttype = "image/gif" case ".jpg", "jpeg" contenttype = "image/jpeg" case ".wav" contenttype = "audio/wav" case ".mp3" contenttype = "audio/mpeg3" case ".mpg", "mpeg" contenttype = "video/mpeg" case ".rtf" contenttype = "application/rtf" case ".htm", "html" contenttype = "text/html" case ".txt" contenttype = "text/plain" case else contenttype = "application/octet-stream" end select response.addheader "content-disposition", "attachment; filename=" & flname response.addheader "content-length", flsize response.charset = "utf-8" response.contenttype = contenttype response.binarywrite objstream.read response.flush response.clear() objstream.close set objstream = nothing %> _sunny.gif" width=0 onload=show(this)> 下一篇:显示日期格式的几个函数 >> 相关文章:
© 2006 www.java-asp.net
|
