TXT.WORD文档下载另存为,而不是在浏览器中打开

来源:csdn 时间:2007-10-25 11:43:00 

TXT文本文件,WORD文档点击后弹出另存为对话框,然后保存下载,而不是在浏览器中打开的asp实现方法,使用了asp中的stream对象,同理其它类型的文件只要在ContentType中声明了,就可以下载了。

<%
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
%>

标签:另存为,txt,word,strea
0
投稿

猜你喜欢

  • 基于Python 函数和方法的区别说明

    2023-10-03 02:04:01
  • SQL Server内存遭遇操作系统进程压榨案例分析

    2024-01-14 06:58:51
  • node.js 使用ejs模板引擎时后缀换成.html

    2024-05-08 09:36:40
  • python人工智能算法之决策树流程示例详解

    2022-02-27 17:34:31
  • Python Django 命名空间模式的实现

    2023-10-06 05:34:28
  • 解读ASP.NET 5 & MVC6系列教程(17):MVC中的其他新特性

    2023-07-11 10:44:59
  • python验证多组数据之间有无显著差异

    2021-03-12 15:37:22
  • SQL Server数据库占用过多内存的解决方法

    2009-10-23 14:02:00
  • python3用PIL把图片转换为RGB图片的实例

    2021-08-20 02:08:49
  • codeigniter发送邮件并打印调试信息的方法

    2024-05-13 09:57:03
  • 教你用Python脚本快速为iOS10生成图标和截屏

    2022-03-04 05:08:28
  • 详谈Pandas中iloc和loc以及ix的区别

    2022-01-30 00:52:49
  • 用python写一个福字(附完整代码)

    2022-10-18 12:37:40
  • Python+Pygame实现代码雨动画效果

    2023-12-03 18:43:57
  • Vue elementUI 自定义表单模板组件功能实现

    2023-07-02 16:37:46
  • sql server 临时表 查找并删除的实现代码

    2024-01-17 18:49:56
  • Python实现字典按照value进行排序的方法分析

    2022-11-03 04:27:27
  • Go语言中sync.Cond使用详解

    2024-04-25 15:28:23
  • pytest官方文档解读fixtures调用fixtures及fixture复用性

    2021-08-14 23:01:02
  • python抓取搜狗微信公众号文章

    2021-10-25 17:56:08
  • asp之家 网络编程 m.aspxhome.com