Du kan ikke direke beskytte en mappes filer. Hvis der nu ligger en fil(secret.exe) i mappen top, kan man jo altid skrive
www.domain.dk/top/secret.exe og hente filen. Du kan oprette en mappe som ikke kan ses fra webben, eller med skjult placering. Og så kan du bruge følgende script:
Du skal bare huske at ændre strPathInfo = "./billeder" til den sti som dine filer ligger i. kodeordet og brugernummeret skal nok også ændres.
<html>
<body>
<%
if (Request.Form("usr")="bruger") AND (Request.Form("pas")="kode") then
session("login")=true
end if
if session("login")<>true then%>
Indtast brugeroplysninger<BR>
<form action="file.asp" method="post">
Usr:<input type="password" name="usr"><BR>
Pas:<input type="password" name="pas"><BR>
<input type="submit" name="send">
</form>
<%
Response.end
end if
strPathInfo = "./billeder"
if len(Request.QueryString("path"))>0 then
strPathInfo=strPathInfo&""&Request.QueryString("path")
end if
strPhysicalPath = Server.MapPath(strPathInfo)%>
<%
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strPhysicalPath)
Set FileContents = objFolder.Files
Set FolderContents = objFolder.SubFolders
if Request.QueryString("act")<>"doStream" then
%>
Følgende mapper findes:<BR>
<A href="file.asp?path=<%=left(strPathInfo,inStr(1,strPathInfo,"/"))%>">..</A><BR>
<%
for each folder in FolderContents%>
<a href="file.asp?path=<%=Request.QueryString("path")&"/"&folder.name%>"><%=folder.name%></A><BR>
<%next%>
<BR>Følgende filer findes:<BR>
<%
for each file in FileContents%>
<a href="file.asp?act=doStream&path=<%=Request.QueryString("path")%>&file=<%=file.name%>" target="_blank"><%=file.name%></A><BR>
<%next
else
Const adTypeBinary = 1
path=strPhysicalPath
strFile=Request.QueryString("file")
strFileType=objFSO.GetFile(path&"\"&strFile).Type
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile(path&"\"&strFile)
Response.AddHeader "content-disposition","attachment; filename=" & strFile
Response.ContentType = strFileType
Response.BinaryWrite(objStream.Read)
Response.Flush()
objStream.Close()
Set objStream = Nothing
end if
Set objFolder = nothing
Set FileContents = nothing
Set FolderContents = nothing
Set objFSO = nothing
%>
<body>
</html>