ASP实现文件直接下载
来源:wdchn.com 发布时间:2008-11-19 15:39:00
在IE进行文档链接时,如果遇到OLE支持的文档,IE会自动调用相应程序打开它,有时候这种功能并不是我们所需的,虽然我们可以提醒用户用鼠标右键-->"目标另存为...."命令来下载文档,但这样毕竟不太友好,本文描述了利用FSO及Stream方法实现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
%>
猜你喜欢
- 先来看看基本的定义:channel是Go语言中的一个核心类型,可以把它看成管道。并发核心单元通过它就可以发送或者接收数据进行通讯,这在一定程
- 一、必要的 python 模块PyTorch 的 Vision 模块提供了图像变换的很多函数.torchvision/transforms/
- Python 正则表达式是什么学习 Python 正则表达式离不开 re 模块,所以本篇博客会配合 re 模块进行编写。re 库是 Pyth
- 本文实例讲述了Python 26进制计算方法。分享给大家供大家参考。具体分析如下:题目是这样的:假设A=1,B=2,C=3...AA=27,
- 加载静态文件在一个网页中,不仅仅只有一个 html 骨架,还需要 css 样式文件, js 执行文件以及一些图片等。因此在 DTL 中加载静
- 组件值校验,即在组件值变化时判断是否满足校验逻辑,若不满足校验逻辑,可以拿到校验错误信息进行错误提示或其他逻辑处理。声明 valueVali
- 相信有很多人有用程序向Excel导数据的需求, 且做过. 一般导出一些文本数据是很方便的, 可选方法很多, 比如拼接文本字符串存.cvs格式
- PyQt之打开保存对话框(QFileDialog)的方法和使用一、控件说明QFileDialog是用于打开和保存文件的标准对话框,继承自QD
- 方法一:def dict_to_numpy_method1(dict): dict_sorted=sorted(dict.iteritems
- 多数应用场景下,我们需要对重要数据进行备份、并放置到一个安全的地方,以备不时之需。常见的 MySQL 数据备份方式有,直接打包复制对应的数据
- 条条框框的报表页面枯燥乏味?不妨给页面加点“新意”!前阵子,在看天气预报的时候,发现免费天气预报的调用代码,瞬间想到可以给我开发的报表“润润
- 如何显示一个等待或欢迎信息? <% Response.Buffer = True %
- 目录1. 什么是闭包2. 闭包的作用2.1) 记忆性2.2) 模拟私有变量3. 闭包的注意点总结1. 什么是闭包闭包:函数本身和该函数声明时
- 以下效率,是奔腾 dual1.6G HZ,1G内存电脑,ie6.0下toggle()与slideToggle("fast"
- Scipy高级科学计算库:和Numpy联系很密切,Scipy一般都是操控Numpy数组来进行科学计算、统计分析,所以可以说是基于Numpy之
- 前言总是记不住字符串拼接,每次都要百度去搜索,所以在这里记录一下,好方便后续的查找,如有错误和问题可以提出,谢谢。字符串拼接分为几种方式,在
- 研究了一段时间酷狗音乐的接口,完美破解了其vip音乐下载方式,想着能更好的追求开源,故写下此篇文章,本文仅供学习参考。虽然没什么
- 首先我是用pycharm完成的,要确定命令行和界面里是同一个环境。如果不确定可以设置再add在新增加的环境里看现在是哪个环境,只要选择已有的
- Etag是URL的Entity Tag,用于标示URL对象是否改变,区分不同语言和Session等等。具体内部含义是使服务器控制的,就像Co
- 计算机顾名思义就是可以做数学计算的机器,因此,计算机程序理所当然地可以处理各种数值。但是,计算机能处理的远不止数值,还可以处理文本、图形、音