DBMNG数据库管理与应用

抓住自己最有兴趣的东西,由浅入深,循序渐进地学……
当前位置:首页 > 服务器配置 > IIS&ASP

asp文件下载输出代码

<%'传入两个参数:strFileWebPath:要下载文件所在的实际网络路径;downloadsavename:在客户端下载提示时保存的文件名
Function DownLoadFile(strFileWebPath,downloadsavename) 
downloadshowname=downloadsavename
strFilename = server.MapPath(strFileWebPath)
Response.Buffer = True 
Response.Clear 
Set Obj = Server.CreateObject("ADODB.Stream") 
Obj.Open 
Obj.Type = 1 
on error resume next 
Set fso = Server.CreateObject("Scripting.FileSystemObject") 
if not fso.FileExists(strFilename) then 
Response.Write("<h1>Error:</h1> 文件不存在<p>") 
Response.End 
end if 
Set Fso = fso.GetFile(strFilename) 
intFilelength = Fso.size 
Obj.LoadFromFile(strFilename) 
if err then 
Response.Write("<h1>Error: </h1>" & err.Description & "<p>") 
Response.End 
end if 
Response.AddHeader "Content-Disposition", "attachment; filename=" &downloadshowname 
Response.AddHeader "Content-Length", intFilelength 
Response.CharSet = "UTF-8" 
Response.ContentType = "application/octet-stream" 
Response.BinaryWrite Obj.Read 
Response.Flush 
Obj.Close 
Set Obj = Nothing 
End Function

%>

<%'传入两个参数:strFileWebPath:要下载文件所在的实际网络路径;downloadsavename:在客户端下载提示时保存的文件名
Function DownLoadFile(strFileWebPath,downloadsavename) 
downloadshowname=downloadsavename
strFilename = server.MapPath(strFileWebPath)
Response.Buffer = True 
Response.Clear 
Set Obj = Server.CreateObject("ADODB.Stream") 
Obj.Open 
Obj.Type = 1 
on error resume next 
Set fso = Server.CreateObject("Scripting.FileSystemObject") 
if not fso.FileExists(strFilename) then 
Response.Write("<h1>Error:</h1> 文件不存在<p>") 
Response.End 
end if 
Set Fso = fso.GetFile(strFilename) 
intFilelength = Fso.size 
Obj.LoadFromFile(strFilename) 
if err then 
Response.Write("<h1>Error: </h1>" & err.Description & "<p>") 
Response.End 
end if 
Response.AddHeader "Content-Disposition", "attachment; filename=" &downloadshowname 
Response.AddHeader "Content-Length", intFilelength 
Response.CharSet = "UTF-8" 
Response.ContentType = "application/octet-stream" 
Response.BinaryWrite Obj.Read 
Response.Flush 
Obj.Close 
Set Obj = Nothing 
End Function 
if request("action")="create" then
DownLoadFile "1.text","a.txt" 
response.End() 
end if
%>
<html>
<head><title></title>
</head>
<body>
dgdgdg
<form>
<input name="a" type="button" value="download" onclick="javascript:window.location='?action=create';" />
</form>
sdfsdfsfsd
</body>
</html>

本站文章内容,部分来自于互联网,若侵犯了您的权益,请致邮件chuanghui423#sohu.com(请将#换为@)联系,我们会尽快核实后删除。
Copyright © 2006-2023 DBMNG.COM All Rights Reserved. Powered by DEVSOARTECH            豫ICP备11002312号-2

豫公网安备 41010502002439号