<%
Set Fs = Server.CreateObject("Scripting.FileSystemObject") 'Fso對象
Set Ado = Server.CreateObject("Adodb.Stream") 'Ado對象
i = 0 '計數器
r = 1024 '每次讀取大小(byte)
FilePath = Server.MapPath("xxxx.rar") '文件路徑
Ado.Mode = 3 '1 讀,2 寫,3 讀寫。
Ado.Type = 1 '1 二進制,2 文本。
Ado.Open
Ado.LoadFromFile(FilePath) '載入文件
Response.AddHeader "Content-Disposition", "attachment; filename=" & Fs.GetFile(FilePath).name '文件名
Response.AddHeader "Content-Length", Ado.size '通知瀏覽器接收的文件大小
Response.ContentType = "application/octet-stream" '通知瀏覽器接受的文件類型(可自己定義,很多種,但一般都用這個.)
While i < Ado.Size '循環讀取直到讀完為止
Response.BinaryWrite Ado.Read(r) '輸出二進制數據流
Response.Flush '立即發送(要求至少256字節),不加的話可能提示超過緩存區。
i = i + r '累加計數器
Wend
Ado.Close '關閉文件對象
Response.End
%>