手机版 | 登录 | 注册 | 留言 | 设首页 | 加收藏
联系客服
当前位置: 网站首页 > 程序技巧 > asp > 文章 当前位置: asp > 文章

Asp中隐藏下载地址

时间:2023-09-11    点击: 次    来源:网络    添加者:佚名 - 小 + 大

<%
Response.Buffer = true
Response.Clear
dim url
Dim fso,fl,flsize
dim Dname
Dim objStream,ContentType,flName,isre,url1
Dim strFileName

strFileName=replace(replace(Request("file"),"/",""),"/","") '传参


strFileName="/files/"&strFileName    ' 改成你你文件的存放路径

If strFileName<>"" Then
'******************************下载文件存放的服务端目录
url=Server.MapPath(strFileName)

else
    Response.Write("no found")
    Response.end 
End If
Set fso=Server.CreateObject("Scripting.FileSystemObject")
Set fl=fso.getfile(url)
flsize=fl.size
flName=fl.name

 

 

Set fl=Nothing
Set fso=Nothing
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = 1
objStream.LoadFromFile url
Select Case lcase(Right(flName, 4))
Case ".asf"
ContentType = "video/x-ms-asf"
Case ".avi"
ContentType = "video/avi"
Case ".doc"
ContentType = "application/msword"
Case ".zip"
ContentType = "application/zip"
Case ".xls"
ContentType = "application/vnd.ms-excel"
Case ".gif"
ContentType = "image/gif"
Case ".jpg", "jpeg"
ContentType = "image/jpeg"
Case ".bmp"
ContentType = "image/bmp"
Case ".ppt"
ContentType = "application/vnd.ms-powerpoint"
Case ".mdb"
ContentType = "application/x-msaccess"
Case ".wav"
ContentType = "audio/wav"
Case ".mp3"
ContentType = "audio/mpeg3"
Case ".mpg", "mpeg"
ContentType = "video/mpeg"
Case ".rtf"
ContentType = "application/rtf"
Case ".htm", "html" ,"htm(1)"
ContentType = "text/html"
Case ".txt"
ContentType = "text/plain"
Case Else
ContentType = "application/octet-stream"
End Select

'  我是用UPload组件上传的,如果重名会产生"(数字)" 后缀,
'  有些主机会阻止下载这类文件,所以这里加一个检查,将Upload组件自动生成的后缀
If InStr(lcase(Right(flName, 1)),")") Then
 flName=mid(flName,1,Len(flName)-3)
End If
Response.AddHeader "Content-Disposition", "attachment; filename="& flName
Response.AddHeader "Content-Length", flsize
Response.Charset = "UTF-8"
Response.ContentType = ContentType
Response.BinaryWrite objStream.Read
Response.Flush
response.Clear()
objStream.Close
Set objStream = Nothing
%>


https://blog.csdn.net/jeefchen/article/details/5297773



分享按钮

上一篇:在ASP中添加修改Access数据库的结构:字段和属性或者sql

下一篇:ASP 隐藏下载地址及防盗链代码

豫ICP备19032584号-1  |   QQ:80571569  |  地址:河南濮阳市  |  电话:13030322310  |  
Copyright © 2024 FE内容付费系统 版权所有,授权www.xingwp.cn使用 Powered by 66FE.COM