我要投稿
  • 您当前的位置:57365.com -> 技术教程 -> 网站建设教程 -> 源码精华 -> 教程内容
  • [ 收藏本页教程 ]
  • TXT.WORD文档下载在本地,而不是在浏览器中打开源码精华教程

    教程作者:佚名    教程来源:不详   教程栏目:源码精华    收藏本页
    <%
    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
    %>

    (出处:

    我要投稿   -   广告合作   -   关于本站   -   友情连接   -   网站地图   -   联系我们   -   版权声明   -   设为首页   -   加入收藏   -   网站留言
    Copyright © 2009 - 20012 www.www.hxswjs.com All Rights Reserved.57365.com 版权所有