最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
文件下载 代码
时间:2022-07-02 23:20:22 编辑:袖梨 来源:一聚教程网
通常想实现用户登录后,才可以下载某此文件,可以用cookies和session来解决用户是否登录,然后根据cookies和session里面记录的值来确定是否给予下载。但是这样做有一个缺点:如果别人知道那个文件的路径,在IE中直接输入路径地址就可以下载了,这样的结果并不是我们想要的。
首先,我们要将保存文件虚拟主机上一个不可访问的目录soft,这样就不可以直接去下载了,所以要想下载,必须通过程序来下载。
index.html文件(用来提供下载)
下载
down.asp
<%
Dim u
u=request.querystring("u")
downloadFile "/soft/123.rar", u
%>
download.asp
<%
'author : lael 2006-2-20
function downloadFile(downfile, downname)
on error resume next
dlfile = server.MapPath(downfile)
Response.Buffer = True
Response.Clear
Set oStream = Server.CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1
Set fso = Server.CreateObject("Scripting.FileSystemObject")
if not fso.FileExists(dlfile) then
set fso = nothing
oStream.Close
Set oStream = nothing
downloadFile = "error:1"
exit function
end if
Set ofile = fso.GetFile(dlfile)
filesize = ofile.size
oStream.LoadFromFile(dlfile)
if err then
err.clear
set ofile = nothing
set fso = nothing
oStream.Close
Set oStream = nothing
downloadFile = "error:2"
exit function
end if
Response.AddHeader "Content-Disposition", "attachment; filename=" & downname
Response.AddHeader "Content-Length", filesize
Response.CharSet="UTF-8"
Response.ContentType="text/plain"
Response.BinaryWrite oStream.Read
Response.Flush
set ofile = nothing
set fso = nothing
oStream.close
Set oStream = nothing
downloadFile = ""
end function
'/////////////////////
%>
来自:http://www.111com.net/detail.asp?id=75
相关文章
- 资讯:三大交易所app下载 全球前三大加密货币交易所 07-02
- 美国运通美联储更新引发瑞波整合热议 07-02
- 火影忍者晓迪达拉怎么玩 07-02
- 火影忍者六道枫怎么玩 07-02
- 像素纪元弓箭手电套CD流玩法分享 07-02
- 地下城与勇士起源2024金秋套外观全职业怎么样 地下城与勇士起源全职业金秋套外观详情 07-02