?? 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"),"\",""),"/","")) '調(diào)用過程
Function downloadFile(Filename)
Filepath =server.MapPath("downloadfile")&"\"& Filename
Response.Buffer = True
Response.Clear
'創(chuàng)建Stream對象
Set Objstream = Server.CreateObject("ADODB.Stream")
Objstream.Open
'數(shù)據(jù)類型為二進制
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="關(guān)閉窗口" 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="關(guān)閉窗口" 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 '將緩沖信息發(fā)送給瀏覽器
Objstream.Close
Set Objstream = Nothing
End Function
%>
</body>
</html>
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -