ASP下载图片,PDF文件等 asp

/ / 2016-01-28   阅读:2500
downpic.asp页面:  <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"&g...
downpic.asp页面: 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<meta http-equiv="Content-Language" content="zh-cn" />
<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />
<script language = "JavaScript" src="/js/jquery-1.4.js" type = "text/javascript"></script>
</head>
<body>
<img src="1.jpg" width="129" height="130" />
<a href="1.jpg" target="_blank">打开</a>
<a href="loadpic.asp?filename=3114_jx.pdf" id="a" title="我要下载">下载</a>
</body>
<script>
</script>
</html>

loadpic.asp页面:
<%  
strFile=Trim(Request.QueryString("filename"))  
if strFile="" or isnull(strFile) then  
Response.Write("<h1>缺少参数</h1>")  
Response.End 
end if  
strFilename = server.MapPath(strFile)  
'response.write strFilename
'response.end
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:" & strFilename & " 文件不存在</h1>")  
Response.End 
end if  
Set f = fso.GetFile(strFilename)  
intFilelength = f.size  
s.LoadFromFile(strFilename)  
if err then  
Response.Write("<h1>Error:" & err.Description & " </h1>")  
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 
%>

我要评论

昵称:
验证码:

最新评论

共0条 共0页 10条/页 首页 上一页 下一页 尾页
意见反馈