| 网站首页 | 文章中心 | 下载中心 | 图片中心 | 中软BT下载站 | 趣味中心 | 雁过留声 | 索尔网络 | 
最新公告:

  没有公告

您现在的位置: 中软网 >> 文章中心 >> 网页设计 >> asp技术 >> 正文
专题栏目
更多内容
最新推荐 更多内容
相关文章
没有相关文章
更多内容
ASP下载实例         ★★★
ASP下载实例
【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口

ASP的功能也很强,我们也可以用来下载文件。

<%
call downloadFile(Request("path"))

function downloadFile(strFile)
strFilename = server.MapPath(strFile)

Response.Buffer = True
Response.Clear

Set s = Server.CreateObject("ADODB.Stream")
s.Open

s.Type = 1

on error resume next


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


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

Response.AddHeader "Content-Disposition", "attachment; filename=" & f.name
Response.AddHeader "Content-Length", intFilelength
Response.CharSet = "UTF-8"
Response.ContentType = "application/octet-stream"

Response.BinaryWrite s.Read
Response.Flush


s.Close
Set s = Nothing


End Function
%>

 

把我上面的代码存成downfile.asp
然后调用downfile.asp?path=yourfile.jpg
就会弹出一个保存框把同目录下的yourfile.jpg下载下来

作者:admin 文章来源:本站原创 点击数: 更新时间:2006-8-22 11:25:27

  • 上一篇文章:

  • 下一篇文章:
  • 【字体: 】【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口
      网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)

    | 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 版权申明
    中软网
      联系方式 QQ:330543128与中软联系     E-mail:solft@126.com ©中软网 版权所有
    信息产业部备案
    浙ICP备05074692号