·您的位置: 首页 » 资源教程 » 编程开发 » ASP » TXT.WORD文档下载在本地,而不是在浏览器中打开

TXT.WORD文档下载在本地,而不是在浏览器中打开

类别: ASP教程  评论数:0 总得分:0
<%
Response.Buffer=true
取得要下载的文件,如果不为空。就下载
dim url,trueurl
url="下载文件路径和下载文件名"
fname=Request("filename")
if fname<>"" then
trueurlurl=server.MapPath("/") &url
end if
set objFso=server.CreateObject("scripting.filesystemobject")
set fn=objFso.GetFile(trueurl)
flsize=fn.size
flname=fn.name
set fn=nothing
set objFso=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 ".ASP", ".ASA", "ASPX", "ASAX", ".MDB"
Response.Write "受保护文件,不能下载."
Response.End
case else
ContentType="appliation/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
%>
-= 资 源 教 程 =-
文 章 搜 索
关键词:
类型:
范围:
纯粹空间 softpure.com
Copyright © 2006-2008 暖阳制作 版权所有
QQ: 15242663 (拒绝闲聊)  Email: faisun@sina.com
 纯粹空间 - 韩国酷站|酷站欣赏|教程大全|资源下载|免费博客|美女壁纸|设计素材|技术论坛   Valid XHTML 1.0 Transitional
百度搜索 谷歌搜索 Alexa搜索 | 粤ICP备19116064号-1