📄 download.asp
字号:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="../conn.asp" -->
<html>
<head>
<title>文件管理_文件下载!</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link href="../style.css" rel="stylesheet">
</head>
<body>
<%call downloadFile(replace(replace(Request("filename"),"\",""),"/","")) '调用过程
Function downloadFile(Filename)
Filepath =server.MapPath("downloadfile")&"\"& Filename
Response.Buffer = True
Response.Clear
'创建Stream对象
Set Objstream = Server.CreateObject("ADODB.Stream")
Objstream.Open
'数据类型为二进制
Objstream.Type = 1
on error resume next
'检查文件是否出错
Set Objfile = Server.CreateObject("Scripting.FileSystemObject")
if not Objfile.FileExists(Filepath) then %>
<table width="560" height="395" border="0" cellpadding="-2" cellspacing="-2"
background="../images/file/download.gif">
<tr>
<td width="510" valign="top"><table width="100%" height="137" border="0"
cellpadding="-2" cellspacing="-2">
<tr>
<td height="121"> </td>
</tr>
</table>
<table width="83%" height="214" border="0" align="center" cellpadding="-2" cellspacing="-2">
<tr>
<td height="91">
<% Response.Write("错误提示:<p>" & Filepath & " 不存在!<p>") %>
</td>
</tr>
<tr>
<td><div align="center"><br>
<form name="form1" >
<input name="myclose" type="button" class="Style_button_del" id="myclose"
value="关闭窗口" onClick="javascrip:window.close()">
</form>
</div></td>
</tr>
</table>
</td>
</tr>
</table>
<%
Response.End()
end if
'获取文件的大小
Set myfile = Objfile.GetFile(Filepath)
intFilelength = myfile.size
Objstream.LoadFromFile(Filepath)
if err then %>
<table width="560" height="395" border="0" cellpadding="-2" cellspacing="-2"
background="../images/file/download.gif">
<tr>
<td width="510" valign="top"><table width="100%" height="131" border="0"
cellpadding="-2" cellspacing="-2">
<tr>
<td height="120"> </td>
</tr>
</table>
<table width="83%" height="189" border="0" align="center" cellpadding="-2" cellspacing="-2">
<tr>
<td height="91">
<% Response.Write("错误提示:<p> " & err.Description & "<p>") %>
</td>
</tr>
<tr>
<td height="98"><div align="center">
<br>
<input name="myclose" type="button" class="Style_button_del"
id="myclose" value="关闭窗口" onClick="javascrip:window.close()">
</div></td>
</tr>
</table>
</form></td>
</tr>
</table>
<%
Response.End
end if
Response.AddHeader "Content-Disposition", "attachment; filename=" & myfile.name
Response.AddHeader "Content-Length", intFilelength
Response.CharSet = "UTF-8"
Response.ContentType = "application/octet-stream"
Response.BinaryWrite Objstream.Read '向HTTP输出写入二进制信息
Response.Flush '将缓冲信息发送给浏览器
Objstream.Close
Set Objstream = Nothing
End Function
%>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -