利用ADODB.Stream使用浏览器下载服务器文件
时间:2008-10-09 12:42:00
本文介绍使用ADODB.Stream组件来下载服务器文件,例如:download.asp?file=相对路径的文件。
就可以把这个文件下载下来,而不是直接在浏览器中打开!
<%
call downloadFile(replace(replace(Request("file"),"\",""),"/",""))
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 exist<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>" & err.Description & "<p>")
Response.End
end if
' send the headers to the users browser
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
%>
标签:Adode,stream,下载,asp
0
投稿
猜你喜欢
.Net行为型设计模式之命令模式(Command)
2024-05-13 09:17:42
Django 2.0版本的新特性抢先看!
2021-01-03 11:10:50
数据库查询排序使用随机排序结果示例(Oracle/MySQL/MS SQL Server)
2024-01-18 20:14:13
Python学习之yaml文件的读取详解
2023-04-20 14:06:42
django连接mysql配置方法总结(推荐)
2024-01-26 21:50:50
python MultipartEncoder传输zip文件实例
2022-04-20 07:22:57
作为Web开发人员,我为什么喜欢Google Chrome浏览器
2011-08-29 15:37:47
python GUI库图形界面开发之PyQt5窗口类QMainWindow详细使用方法
2021-03-16 08:53:47
PHP概率计算函数汇总
2023-11-19 08:06:19
使用python求解迷宫问题的三种实现方法
2022-10-25 01:16:35
关于MySQL与Golan分布式事务经典的七种解决方案
2024-01-15 00:49:33
MySql字符串拆分实现split功能(字段分割转列)
2024-01-15 03:12:03
SEO与“nofollow”及“external nofollow”
2007-12-15 09:31:00
pytorch实现线性回归以及多元回归
2023-04-13 02:15:27
springboot 启动时初始化数据库的步骤
2024-01-26 18:32:57
用err.raise自定义错误信息
2008-02-20 12:48:00
简单解决Windows中MySQL的中文乱码与服务启动问题
2024-01-21 00:58:43
MySQL常见优化方案汇总
2024-01-23 05:29:35
Python命令启动Web服务器实例详解
2022-10-09 11:53:42
Sql Server 2008完全卸载方法(其他版本类似)第1/2页
2024-01-14 01:20:09