檔案名:download.asp
<%
dim stream
dim contents
dim filename
dim fileext
const adtypebinary = 1
filename = request.querystring("filename")
if filename = "" then
response.write "無效檔案名."
response.end
end if
' 下面是不希望下載下傳的檔案
fileext = mid(filename, instrrev(filename, ".") + 1)
select case ucase(fileext)
case "asp", "asa", "aspx", "asax", "mdb"
response.write "受保護檔案,不能下載下傳."
response.end
end select
' 下載下傳這個檔案
response.clear
response.contenttype = "application/octet-stream"
response.addheader "content-disposition", "p_w_upload; filename=" & filename
set stream = server.createobject("adodb.stream")
stream.type = adtypebinary
stream.open
stream.loadfromfile server.mappath(filename)
while not stream.eos
response.binarywrite stream.read(1024 * 64)
wend
stream.close
set stream = nothing
response.flush
response.end
%>
使用:download.asp?filename=/files/my.doc
把你的doc檔案放到根目錄files下,你也可以放到其它地方了。
如:
<a href="download.asp?filename=/files/my.doc">點選下載下傳</a>