会员: 密码:  免费注册 | 忘记密码 | 会员登录 网页功能: 加入收藏 设为首页 网站搜索  
 安全技术技术文档
  · 安全配制
  · 工具介绍
  · 黑客教学
  · 防火墙
  · 漏洞分析
  · 破解专题
  · 黑客编程
  · 入侵检测
 安全技术论坛
  · 安全配制
  · 工具介绍
  · 防火墙
  · 黑客入侵
  · 漏洞检测
  · 破解方法
  · 杀毒专区
 安全技术工具下载
  · 扫描工具
  · 攻击程序
  · 后门木马
  · 拒绝服务
  · 口令破解
  · 代理程序
  · 防火墙
  · 加密解密
  · 入侵检测
  · 攻防演示
技术文档 > Web开发 > ASP
ASP实现文件直接下载
发表日期:2005-08-26 23:38:51作者:c 出处:CSDN  

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


 

返回顶部】 【打印本页】 【关闭窗口

关于我们 / 给我留言 / 版权举报 / 意见建议 / 网站编程QQ群   
Copyright ©2003- 2024 Lihuasoft.net webmaster(at)lihuasoft.net 加载时间 0.00166