相關(guān)資訊
本類常用軟件
-
福建農(nóng)村信用社手機(jī)銀行客戶端下載下載量:584204
-
Windows優(yōu)化大師下載量:416896
-
90美女秀(視頻聊天軟件)下載量:366961
-
廣西農(nóng)村信用社手機(jī)銀行客戶端下載下載量:365699
-
快播手機(jī)版下載量:325855
本文跟大家一起分享到的是關(guān)于利用ASP實(shí)現(xiàn)隱藏文件實(shí)際下載路徑,對(duì)ASP感興趣的朋友們可以好好學(xué)習(xí)一下。
如果我們知道一個(gè)靜態(tài)文件的實(shí)際路徑如:http://www.xx.com/download/51windows.pdf,如果服務(wù)器沒有作特別的限制設(shè)置,我們就可以毫不費(fèi)力的把它下載下來!當(dāng)網(wǎng)站提供51Windows.pdf下載時(shí),怎么樣才能讓下載者無法得到他的實(shí)際路徑呢!本文就來介紹如何使用ASP來隱藏文件的實(shí)際下載路徑。
我們?cè)诠芾砭W(wǎng)站文件時(shí),可以把擴(kuò)展名一樣的文件放在同一個(gè)目錄下,起一個(gè)比較特別名字,例如放pdf文件目錄為the_pdf_file_s,把下面代碼另存為down.asp,他的網(wǎng)上路徑為http://www.xx.com/down.asp,我們就可以用http://www.xx.com/down.asp?FileName=51windows.pdf來下載這個(gè)文件了,而且下載者無法看到這個(gè)文件實(shí)際下載路徑的!在down.asp中我們還可以設(shè)置下載文件是否需要登陸,判斷下載的來源頁是否為外部網(wǎng)站,從而可以做到防止文件被盜鏈。
示例代碼:
<%
From_url = Cstr(Request.ServerVariables("HTTP_REFERER"))
Serv_url = Cstr(Request.ServerVariables("SERVER_NAME"))
if mid(From_url,8,len(Serv_url)) <> Serv_url then
response.write "非法鏈接!" '防止盜鏈
response.end
end if
if Request.Cookies("Logined")="" then
response.redirect "/login.asp" '需要登陸!
end if
Function GetFileName(longname)'/folder1/folder2/file.asp=>file.asp
while instr(longname,"/")
longname = right(longname,len(longname)-1)
wend
GetFileName = longname
End Function
Dim Stream
Dim Contents
Dim FileName
Dim TrueFileName
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
if lcase(right(FileName,3))="gif" or lcase(right(FileName,3))="jpg" or lcase(right(FileName,3))="png" then
Response.ContentType = "image/*" '對(duì)圖像文件不出現(xiàn)下載對(duì)話框
else
Response.ContentType = "application/ms-download"
end if
Response.AddHeader "content-disposition", "attachment; filename=" & GetFileName(Request.QueryString("FileName"))
Set Stream = server.CreateObject("ADODB.Stream")
Stream.Type = adTypeBinary
Stream.Open
if lcase(right(FileName,3))="pdf" then '設(shè)置pdf類型文件目錄
TrueFileName = "/the_pdf_file_s/"&FileName
end if
if lcase(right(FileName,3))="doc" then '設(shè)置DOC類型文件目錄
TrueFileName = "/my_D_O_C_file/"&FileName
end if
if lcase(right(FileName,3))="gif" or lcase(right(FileName,3))="jpg" or lcase(right(FileName,3))="png" then
TrueFileName = "/all_images_/"&FileName '設(shè)置圖像文件目錄
end if
Stream.LoadFromFile Server.MapPath(TrueFileName)
While Not Stream.EOS
Response.BinaryWrite Stream.Read(1024 * 64)
Wend
Stream.Close
Set Stream = Nothing
Response.Flush
Response.End
%>