stingerman_1
asked on
browse for file in web directory
I'm currently using classic asp to write an app. I would like to find a way to be able to browse a specified directory on the webserver and take the selected file and write it as text to a text field. Does anyone know of a way to do this?
thanks in advance,
stingerman_1
thanks in advance,
stingerman_1
You can use this for a file browser on your local site:
http://nscripts.havocaos.com/wumpus/download.asp
I use it on my dump sub-domain :) Once configured it's really good. Very nice interface.
http://nscripts.havocaos.com/wumpus/download.asp
I use it on my dump sub-domain :) Once configured it's really good. Very nice interface.
ASKER
I am trying the wumpus route, but when I access the page I get the following error:
Microsoft VBScript runtime error '800a0009'
Subscript out of range: 'split(...)'
/wumpus/index.asp, line 29
Any clues? I did a response.write and it appeared as though my path was correct.
Microsoft VBScript runtime error '800a0009'
Subscript out of range: 'split(...)'
/wumpus/index.asp, line 29
Any clues? I did a response.write and it appeared as though my path was correct.
Can you post your code? I'm not familiar with how they've done it on that site.
ASKER
<% @CodePage = 1257 Language = "VBScript" %>
<% Response.Buffer = true %>
<!-- #include file="config.asp" -->
<!-- #include file="stringbuilder.asp" -->
<%
' start a-profilin'
if bDebugMode then
if bSoftWing then
dim objProfiler
set objProfiler = Server.CreateObject("Softw ing.Profil er")
objProfiler.ProfileStart()
else
dim dDebugTimer
dDebugTimer = timer
end if
end if
' some needed variables
dim sCurrentDir, sHost, sListPath, iFolderCount, iTotalFolderSize, iFileCount, iTotalFileSize, debug, view, vbDir
iFolderCount = 0 : iTotalFolderSize = 0 : iFileCount = 0 : iTotalFileSize = 0
' are we running as an index doc or error doc?
select case sRunMode
case "error"
' get the domain and port, eg. http://www.foo.com:80
sHost = sDomain & ":" & request.servervariables("S ERVER_PORT ")
' get the requested URL
response.Write request.servervariables("Q UERY_STRIN G") & "-this is the query_string that isn't displaying "
***************** LINE THAT ERRORS OUT!! ************************
sCurrentDir = split(request.servervariab les("QUERY _STRING"), ";")(1)
************************** ********** ********** ********** ******
' remove the host part
sCurrentDir = replace(sCurrentDir, sHost, "")
case "index"
' get the base URL
sCurrentDir = request.servervariables("S CRIPT_NAME ")
' remove the script name
sCurrentDir = left(sCurrentDir, instrrev(sCurrentDir, "/"))
case else
response.write "Error: sRunMode must be either ""error"" or ""index"". Please check your config.asp file."
response.end
end select
' filesystem stuff
dim fs, fld, f
set fs = server.createobject("Scrip ting.FileS ystemObjec t")
set fld = fs.getfolder(server.mappat h(sCurrent Dir))
' alternating background color
dim sBG
sBG = "tc2"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>index of <%=sCurrentDir%></title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<style type="text/css" media="all">
/* general stuff */
body {margin:0}
a, a:visited {text-decoration:none; color:#000000}
a:hover {text-decoration:none; color:#757575}
img {border:0}
/* detailed view */
table {width:100%; border:0; padding:0; margin:0; empty-cells:show}
th {text-align:left; font-weight:bold; background-color: buttonface; cursor:default;
border-width:1px; border-style: solid; border-color: buttonhighlight buttonshadow buttonshadow buttonhighlight;
}
th img {vertical-align:middle}
th, td {font-family:verdana, serif; font-size:11px; margin:0; padding:3px}
tr.tc {background-color:#fff}
tr.tc2 {background-color:#eee}
/* tiled view */
table.tiled {float:left; width:33.3%}
table.tiled:hover {background-color:buttonfa ce}
table.tiled td.icon {width:32px}
span.small {font-family:verdana, serif; font-size:9px; color:#757575}
/* thumbnail view */
table.thumb {float:left; width:120px; height:120px; margin:8px}
table.thumb td {white-space:nowrap; text-align:center}
table.thumb td.icon {border:2px solid buttonface; width:120px; height:120px}
table.thumb td.icon:hover {border:2px solid #9999dd}
table.thumb td.icon img {vertical-align:middle}
img.thumbnail {max-width:100px; max-height:100px;
width:expression(this.widt h > 100 ? 100 : true);
height:expression(this.hei ght > 100 ? 100 : true);
}
/* tree view */
ul {list-style-type:none; font-family:verdana, serif; font-size:11px; padding-left:18px; _padding-left:0}
li {padding-bottom:2px}
li img {vertical-align:middle}
li.p {list-style-image:url('<%= sDomain & sInstDir%>/images/dir_coll apse.gif') }
li.c {list-style-image:url('<%= sDomain & sInstDir%>/images/dir_expa nd.gif')}
li.i {display:inline}
/* footer */
table.footer { clear:both;
border-width:1px; border-style: solid; border-color: buttonshadow buttonhighlight buttonhighlight buttonshadow;
}
table.footer th {font-weight:normal; text-align:center}
table.footer th a img {vertical-align:middle}
/* debug */
div.debug {text-align:center; font-family:verdana, serif; font-size:10px; color:#757575}
a.debug, a.debug:visited {text-decoration: none; color:#757575}
a.debug:hover {text-decoration:none; color:#000000}
</style>
<!--[if lt IE 7]>
<script type="text/javascript" src="<%=sDomain & sInstDir%>/pngfix.js"></sc ript>
<![endif]-->
<script type="text/javascript" src="<%=sDomain & sInstDir%>/sort.asp"></scr ipt>
</head>
<body>
<!-- #include file="header.html" -->
<table cellspacing="0">
<tr><th><img src="<%=sDomain & sInstDir%>/icons/folder_op en_16.png" alt="<%=sCurrentDir%>" /> <%=sCurrentDir%></th></tr>
</table>
<%
view = request.cookies("view")
if len(view) = 0 then view = sDefaultView
set vbDir = new StringBuilder
select case view
'------------
' tiled view-
'------------
case "tiles"
' the "up one level" icon
vbDir.append("<table class=""tiled""><tr>" & vbCRLF)
vbDir.append("<td class=""icon""><a href="".."" title=""Up one level"">" & vbCRLF)
vbDir.append("<img src=""" & GetFolderImg("up") & """ alt=""Up one level"" /></a></td>" & vbCRLF)
vbDir.append("<td><a href="".."" title=""Up one level"">Up one level</a></td>" & vbCRLF)
vbDir.append("</tr></table >" & vbCRLF)
' subfolders
for each f in fld.subfolders
if CanViewFile(f) then
vbDir.append("<table class=""tiled""><tr>" & vbCRLF)
vbDir.append("<td class=""icon""><a href=""" & CleanURL(f.name) & """ title=""Folder"">" & vbCRLF)
vbDir.append("<img src=""" & GetFolderImg("closed") & """ alt=""Folder"" /></a></td>" & vbCRLF)
vbDir.append("<td><a href=""" & CleanURL(f.name) & """ title=""Folder"">" & f.name & "</a></td>" & vbCRLF)
vbDir.append("</tr></table >" & vbCRLF)
iFolderCount = iFolderCount + 1
iTotalFolderSize = iTotalFolderSize + f.size
end if
next
' files
for each f in fld.files
if CanViewFile(f) then
vbDir.append("<table class=""tiled""><tr>" & vbCRLF)
vbDir.append("<td class=""icon""><a href=""" & CleanURL(f.name) & """ title=""" & f.type & """>" & vbCRLF)
vbDir.append("<img src=""" & GetExtImg(f.name) & """ alt=""" & f.type & """ /></a></td>" & vbCRLF)
vbDir.append("<td><a href=""" & CleanURL(f.name) & """ title=""" & f.type & """>" & f.Name & "</a><br />")
vbDir.append("<span class=""small"">" & FormatFileSize(f.size) & "</span></td>" & vbCRLF)
vbDir.append("</tr></table >" & vbCRLF)
iFileCount = iFileCount + 1
iTotalFileSize = iTotalFileSize + f.size
end if
next
response.write vbDir.tostring()
'---------------
'-detailed view-
'---------------
case "details"
' table header
vbDir.append("<table cellspacing=""0"" id=""details-table"">" & vbCRLF)
vbDir.append("<colgroup><c ol width=""20px"" /><col width=""40%"" /><col width=""20%"" /><col width=""20%"" /><col /></colgroup>" & vbCRLF)
vbDir.append("<thead id=""header"">" & vbCRLF)
vbDir.append("<tr>" & vbCRLF)
vbDir.append("<th> </ th>" & vbCRLF)
vbDir.append("<th onclick=""sortTables(1)""> Name </th>" & vbCRLF)
vbDir.append("<th onclick=""sortTables(2)""> Size </th>" & vbCRLF)
vbDir.append("<th onclick=""sortTables(3)""> Type </th>" & vbCRLF)
vbDir.append("<th onclick=""sortTables(4)""> Last modified </th>" & vbCRLF)
vbDir.append("</tr>" & vbCRLF)
' the "up one level" link
vbDir.append("<tr class=""tc"">" & vbCRLF)
vbDir.append("<td><a href="".."" title=""Up one level"">" & vbCRLF)
vbDir.append("<img src=""" & GetFolderImg("up") & """ alt=""Up one level"" /></a></td>" & vbCRLF)
vbDir.append("<td><a href="".."" title=""Up one level"">..</a></td>" & vbCRLF)
vbDir.append("<td> </ td>" & vbCRLF)
vbDir.append("<td>Up one level</td>" & vbCRLF)
vbDir.append("<td> </ td>" & vbCRLF)
vbDir.append("</tr></thead >" & vbCRLF)
' subfolders
vbDir.append("<tbody id=""subfolders"">" & vbCRLF)
for each f in fld.subfolders
if CanViewFile(f) then
vbDir.append("<tr class=""" & sBG & """>" & vbCRLF)
vbDir.append("<td><a href=""" & CleanURL(f.name) & """ title=""Folder"">" & vbCRLF)
vbDir.append("<img src=""" & GetFolderImg("closed") & """ alt=""" & f.type & """ /></a></td>" & vbCRLF)
vbDir.append("<td><a href=""" & CleanURL(f.name) & """ title=""Folder"">" & f.name & "</a></td>" & vbCRLF)
vbDir.append("<td>" & FormatFileSize(f.size) & "</td>" & vbCRLF)
vbDir.append("<td>" & f.type & "</td>" & vbCRLF)
vbDir.append("<td>" & f.DateLastModified & "</td>" & vbCRLF)
vbDir.append("</tr>" & vbCRLF)
SwapBG
iFolderCount = iFolderCount + 1
iTotalFolderSize = iTotalFolderSize + f.size
end if
next
vbDir.append("</tbody>" & vbCRLF)
'files
vbDir.append("<tbody id=""files"">" & vbCRLF)
for each f in fld.files
if CanViewFile(f) then
vbDir.append("<tr class=""" & sBG & """>" & vbCRLF)
vbDir.append("<td><a href=""" & CleanURL(f.name) & """ title=""" & f.type & """>" & vbCRLF)
vbDir.append("<img src=""" & GetExtImg(f.name) & """ alt=""" & f.type & """ /></a></td>" & vbCRLF)
vbDir.append("<td><a href=""" & CleanURL(f.Name) & """ title=""" & f.type & """>" & f.name & "</a></td>" & vbCRLF)
vbDir.append("<td>" & FormatFileSize(f.size) & "</td>" & vbCRLF)
vbDir.append("<td>" & f.type & "</td>" & vbCRLF)
vbDir.append("<td>" & f.datelastmodified & "</td>" & vbCRLF)
vbDir.append("</tr>" & vbCRLF)
SwapBG
iFileCount = iFileCount + 1
iTotalFileSize = iTotalFileSize + f.size
end if
next
vbDir.append("</tbody>" & vbCRLF)
vbDir.append("</table>" & vbCRLF)
response.write vbDir.tostring()
'-----------
'-tree view-
'-----------
case "tree"
sListPath = sDomain
' the root folder
vbDir.append("<ul><li class=""p""><a href=""" & CleanURL(sListPath) & """ title=""" & sListPath & """>" & vbCRLF)
vbDir.append("<img src=""" & GetFolderImg("up") & """ alt="""" /> " & sListPath & "</a></li>" & vbCRLF)
vbDir.append("<li class=""i"">" & vbCRLF)
' path to the current folder
dim path, i
path = split(sCurrentDir, "/")
for i = 1 to ubound(path) - 1
sListPath = sListPath & "/" & path(i)
vbDir.append("<ul><li class=""p""><a href=""" & CleanURL(sListPath) & """ title=""" & sListPath & """>" & vbCRLF)
vbDir.append("<img src=""" & GetFolderImg("open") & """ alt="""" /> " & path(i) & "</a></li><li class=""i"">" & vbCRLF)
next
' subfolders
vbDir.append("<ul>" & vbCRLF)
for each f in fld.subfolders
if CanViewFile(f) then
vbDir.append("<li class=""c""><a href=""" & CleanURL(f.name) & """ title=""" & f.name & """>" & vbCRLF)
vbDir.append("<img src=""" & GetFolderImg("closed") & """ alt=""" & f.type & """ /> " & vbCRLF)
vbDir.append(f.name & "</a></li>" & vbCRLF)
iFolderCount = iFolderCount + 1
iTotalFolderSize = iTotalFolderSize + f.size
end if
next
' files
for each f in fld.files
if CanViewFile(f) then
vbDir.append("<li><a href=""" & CleanURL(f.name) & """ title=""" & f.name & """>" & vbCRLF)
vbDir.append("<img src=""" & GetExtImg(f.name) & """ alt=""" & f.type & """ /> " & vbCRLF)
vbDir.append(f.name & "</a></li>" & vbCRLF)
iFileCount = iFileCount + 1
iTotalFileSize = iTotalFileSize + f.size
end if
next
' close all those lists correctly
vbDir.append("</ul>" & vbCRLF)
for i = 1 to ubound(path)
vbDir.append("</li></ul>" & vbCRLF)
next
response.write vbDir.tostring()
'----------------
'-thumbnail view-
'----------------
case "thumbs"
' the "up one level" icon
vbDir.append("<table class=""thumb""><tr>" & vbCRLF)
vbDir.append("<td class=""icon""><a href="".."" title=""Up one level"">" & vbCRLF)
vbDir.append("<img src=""" & GetFolderImg("up") & """ alt=""Up one level"" /></a></td></tr>" & vbCRLF)
vbDir.append("<tr><td><a href="".."" title=""Up one level"">Up one level</a></td>" & vbCRLF)
vbDir.append("</tr></table >" & vbCRLF)
' subfolders
for each f in fld.subfolders
if CanViewFile(f) then
vbDir.append("<table class=""thumb""><tr>" & vbCRLF)
vbDir.append("<td class=""icon""><a href=""" & CleanURL(f.name) & """ title=""Folder"">" & vbCRLF)
vbDir.append("<img src=""" & GetFolderImg("closed") & """ alt=""Folder"" /></a></td></tr>" & vbCRLF)
vbDir.append("<tr><td><a href=""" & CleanURL(f.name) & """ title=""Folder"">")
if len(f.name) > 12 then
vbDir.append(left(f.name, 12) & "...")
else
vbDir.append(f.name)
end if
vbDir.append("</a></td>" & vbCRLF)
vbDir.append("</tr></table >" & vbCRLF)
iFolderCount = iFolderCount + 1
iTotalFolderSize = iTotalFolderSize + f.size
end if
next
' files
for each f in fld.files
if CanViewFile(f) then
vbDir.append("<table class=""thumb""><tr>" & vbCRLF)
vbDir.append("<td class=""icon""><a href=""" & CleanURL(f.name) & """ title=""" & f.type & """>" & vbCRLF)
if IsImageFile(f.name) then
if bUseDotNetThumbs then
vbDir.append("<img src=""" & sDomain & sInstDir & "/getimage.aspx?img=" & sCurrentDir &_
CleanURL(f.name) & "&w=" & iThumbWidth & """ alt=""" & f.type & """ />")
else
vbDir.append("<img src=""" & CleanURL(f.name) & """ alt=""" & f.type & """ class=""thumbnail"" />")
end if
else
vbDir.append("<img src=""" & GetExtImg(f.Name) & """ alt=""" & f.type & """ />")
end if
vbDir.append("</a></td></t r>" & vbCRLF)
vbDir.append("<tr><td><a href=""" & CleanURL(f.name) & """ title=""" & f.type & """>")
if len(f.name) > 12 then
vbDir.append(left(f.name, 12) & "...")
else
vbDir.append(f.name)
end if
vbDir.append("</a></td>" & vbCRLF)
vbDir.append("</tr></table >" & vbCRLF)
iFileCount = iFileCount + 1
iTotalFileSize = iTotalFileSize + f.size
end if
next
response.write vbDir.tostring()
end select
%>
<table cellspacing="0" class="footer">
<tr>
<th>
<img src="<%=sDomain & sInstDir%>/icons/folder_cl osed_16.pn g" alt="Total Folders" /> Total Folders:
<strong><%=iFolderCount%>< /strong>&n bsp; &nbs p;
<img src="<%=sDomain & sInstDir%>/icons/folder_cl osed_16.pn g" alt="Total Folders Size" /> Total Folders Size:
<strong><%=FormatFileSize( iTotalFold erSize)%>< /strong>&n bsp; &nbs p;
<img src="<%=sDomain & sInstDir%>/icons/file_blan k_16.png" alt="Total Files" /> Total Files:
<strong><%=iFileCount%></s trong>&nbs p; &n bsp;
<img src="<%=sDomain & sInstDir%>/icons/file_blan k_16.png" alt="Total Files Size" /> Total Files Size:
<strong><%=FormatFileSize( iTotalFile Size)%></s trong>
</th>
</tr>
<tr>
<th>
<a href="<%=sDomain & sInstDir%>/setcookie.asp?v iew=tree" title="Tree View">
<img src="<%=sDomain & sInstDir%>/images/view_tre e.png" alt="Tree View" />
</a>
<a href="<%=sDomain & sInstDir%>/setcookie.asp?v iew=detail s" title="Detailed View">
<img src="<%=sDomain & sInstDir%>/images/view_det ails.png" alt="Detailed View" />
</a>
<a href="<%=sDomain & sInstDir%>/setcookie.asp?v iew=tiles" title="Tiled View">
<img src="<%=sDomain & sInstDir%>/images/view_til es.png" alt="Tiled View" />
</a>
<a href="<%=sDomain & sInstDir%>/setcookie.asp?v iew=thumbs " title="Thumbnail View">
<img src="<%=sDomain & sInstDir%>/images/view_thu mbs.png" alt="Thumbnail View" />
</a>
</th>
</tr>
</table>
<div class="debug">
<br />
<%
if bDebugMode then
if bSoftWing then
debug = FormatNumber((objProfiler. ProfileSto p() / 10000), 8, -1, 0, 0)
set objProfiler = nothing
else
debug = FormatNumber((timer - dDebugTimer), 8, -1, 0, 0)
end if
response.write "Seconds to generate: [" & debug & "]<br />"
end if
%>
<strong><a class="debug" href="http://nscripts.havocaos.com" title="Wumpus" rel="external">Wumpus v1.1</a></strong> - © 2005
<a class="debug" href="mailto:indrek.haav@g mail.com" title="indrek.haav@gmail.c om">Indrek Haav</a><br />
<!-- #include file="footer.html" -->
</div>
</body>
</html>
<%
' clean up
set fld = nothing
set fs = nothing
set vbDir = nothing
set objProfiler = nothing
%>
<%
function GetFileExt(byref filename)
' Returns the file extension for a given filename
if instr(filename, ".") > 0 then
GetFileExt = lcase(right( filename, len(filename) - instrrev(filename, ".") ))
else
GetFileExt = ""
end if
end function
function GetExtImg(byref filename)
' Returns the file icon for a given file extension
dim sResult, sExt
sExt = GetFileExt(filename)
select case sExt
' text files
case "txt", "css", "log", "ini"
sResult = "txt"
' scripts
case "asp", "php", "pl", "plx", "cgi", "aspx", "asa", "js", "xml"
sResult = "asp"
case "java", "jsp"
sResult = "java"
' html
case "htm", "html", "shtml"
sResult = "html"
' office documents
case "doc", "rtf"
sResult = "doc"
case "xls"
sResult = "xls"
case "ppt"
sResult = "ppt"
case "mdb"
sResult = "mdb"
' binaries
case "exe", "msi"
sResult = "exe"
case "dll"
sResult = "dll"
' disk images
case "iso", "img", "bin"
sResult = "iso"
' executables
case "bat", "class"
sResult = "bat"
' archives
case "zip", "rar", "ace", "jar", "tar"
sResult = "zip"
' images
case "gif"
sResult = "gif"
case "tif", "jpg", "jpeg", "bmp"
sResult = "jpg"
case "png", "psd"
sResult = "png"
' pdf
case "pdf"
sResult = "pdf"
' flash
case "swf", "fla"
sResult = "flash"
' video
case "avi", "mpeg", "mpg"
sResult = "avi"
case "mov"
sResult = "mov"
' audio
case "mp3", "mp4", "wav", "ogg", "aac", "au", "aiff"
sResult = "mp3"
' windows media
case "wmv", "wma", "asf", "wmf"
sResult = "wmv"
' blank
case "blank", ""
sResult = "blank"
' others
case else
sResult = "foo"
end select
GetExtImg = sDomain & sInstDir & "/icons/file_" & sResult & GetIconSize() & ".png"
end function
function GetFolderImg(byref fld)
' Returns the folder icon
GetFolderImg = sDomain & sInstDir & "/icons/folder_" & fld & GetIconSize() & ".png"
end function
function GetIconSize()
' Returns the icon size - 16, 32 or 48 pixels - based on the currently active view mode
if view = "thumbs" then
GetIconSize = "_48"
elseif view = "tiles" then
GetIconSize = "_32"
else
GetIconSize = "_16"
end if
end function
function FormatFileSize(byref filesize)
' Formats the file size
if filesize > 1073741824 then
FormatFileSize = FormatNumber((filesize / 1073741824), 2, -1, 0, 0) & " GB"
elseif filesize > 1048576 then
FormatFileSize = FormatNumber((filesize / 1048376), 2, -1, 0, 0) & " MB"
elseif filesize > 1024 then
FormatFileSize = FormatNumber((filesize / 1024), 2, -1, 0, 0) & " KB"
else
FormatFileSize = filesize & " bytes"
end if
end function
sub SwapBG()
' Toggles the row background for detailed view
if sBG = "tc" then
sBG = "tc2"
else
sBG = "tc"
end if
end sub
function CleanURL(byref sURL)
sURL = replace(sURL, " ", "%20")
sURL = replace(sURL, "&", "&")
CleanURL = sURL
end function
function CanViewFile(byref f)
' Determines whether or not the current file or folder can be viewed
CanViewFile = true
' should we show hidden and system files?
if (f.attributes AND 2) and not bShowHidden then CanViewFile = false
if (f.attributes AND 4) and not bShowSystem then CanViewFile = false
' is the file extension blocked?
if instr(sIgnoreExt, GetFileExt(f.name)) > 0 and f.type <> "File Folder" then CanViewFile = false
' hide index documents?
if (f.name = "default.asp" or f.name = "index.asp") and bHideIndexDoc then CanViewFile = false
end function
function IsImageFile(byref filename)
' Decides whether or not the current file is an image
' Image files get their thumbnail rendered in thumbs view
select case GetFileExt(filename)
case "jpg", "jpeg", "gif", "bmp", "png"
IsImageFile = true
case else
IsImageFile = false
end select
end function
%>
<% Response.Buffer = true %>
<!-- #include file="config.asp" -->
<!-- #include file="stringbuilder.asp" -->
<%
' start a-profilin'
if bDebugMode then
if bSoftWing then
dim objProfiler
set objProfiler = Server.CreateObject("Softw
objProfiler.ProfileStart()
else
dim dDebugTimer
dDebugTimer = timer
end if
end if
' some needed variables
dim sCurrentDir, sHost, sListPath, iFolderCount, iTotalFolderSize, iFileCount, iTotalFileSize, debug, view, vbDir
iFolderCount = 0 : iTotalFolderSize = 0 : iFileCount = 0 : iTotalFileSize = 0
' are we running as an index doc or error doc?
select case sRunMode
case "error"
' get the domain and port, eg. http://www.foo.com:80
sHost = sDomain & ":" & request.servervariables("S
' get the requested URL
response.Write request.servervariables("Q
***************** LINE THAT ERRORS OUT!! ************************
sCurrentDir = split(request.servervariab
**************************
' remove the host part
sCurrentDir = replace(sCurrentDir, sHost, "")
case "index"
' get the base URL
sCurrentDir = request.servervariables("S
' remove the script name
sCurrentDir = left(sCurrentDir, instrrev(sCurrentDir, "/"))
case else
response.write "Error: sRunMode must be either ""error"" or ""index"". Please check your config.asp file."
response.end
end select
' filesystem stuff
dim fs, fld, f
set fs = server.createobject("Scrip
set fld = fs.getfolder(server.mappat
' alternating background color
dim sBG
sBG = "tc2"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>index of <%=sCurrentDir%></title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<style type="text/css" media="all">
/* general stuff */
body {margin:0}
a, a:visited {text-decoration:none; color:#000000}
a:hover {text-decoration:none; color:#757575}
img {border:0}
/* detailed view */
table {width:100%; border:0; padding:0; margin:0; empty-cells:show}
th {text-align:left; font-weight:bold; background-color: buttonface; cursor:default;
border-width:1px; border-style: solid; border-color: buttonhighlight buttonshadow buttonshadow buttonhighlight;
}
th img {vertical-align:middle}
th, td {font-family:verdana, serif; font-size:11px; margin:0; padding:3px}
tr.tc {background-color:#fff}
tr.tc2 {background-color:#eee}
/* tiled view */
table.tiled {float:left; width:33.3%}
table.tiled:hover {background-color:buttonfa
table.tiled td.icon {width:32px}
span.small {font-family:verdana, serif; font-size:9px; color:#757575}
/* thumbnail view */
table.thumb {float:left; width:120px; height:120px; margin:8px}
table.thumb td {white-space:nowrap; text-align:center}
table.thumb td.icon {border:2px solid buttonface; width:120px; height:120px}
table.thumb td.icon:hover {border:2px solid #9999dd}
table.thumb td.icon img {vertical-align:middle}
img.thumbnail {max-width:100px; max-height:100px;
width:expression(this.widt
height:expression(this.hei
}
/* tree view */
ul {list-style-type:none; font-family:verdana, serif; font-size:11px; padding-left:18px; _padding-left:0}
li {padding-bottom:2px}
li img {vertical-align:middle}
li.p {list-style-image:url('<%=
li.c {list-style-image:url('<%=
li.i {display:inline}
/* footer */
table.footer { clear:both;
border-width:1px; border-style: solid; border-color: buttonshadow buttonhighlight buttonhighlight buttonshadow;
}
table.footer th {font-weight:normal; text-align:center}
table.footer th a img {vertical-align:middle}
/* debug */
div.debug {text-align:center; font-family:verdana, serif; font-size:10px; color:#757575}
a.debug, a.debug:visited {text-decoration: none; color:#757575}
a.debug:hover {text-decoration:none; color:#000000}
</style>
<!--[if lt IE 7]>
<script type="text/javascript" src="<%=sDomain & sInstDir%>/pngfix.js"></sc
<![endif]-->
<script type="text/javascript" src="<%=sDomain & sInstDir%>/sort.asp"></scr
</head>
<body>
<!-- #include file="header.html" -->
<table cellspacing="0">
<tr><th><img src="<%=sDomain & sInstDir%>/icons/folder_op
</table>
<%
view = request.cookies("view")
if len(view) = 0 then view = sDefaultView
set vbDir = new StringBuilder
select case view
'------------
' tiled view-
'------------
case "tiles"
' the "up one level" icon
vbDir.append("<table class=""tiled""><tr>" & vbCRLF)
vbDir.append("<td class=""icon""><a href="".."" title=""Up one level"">" & vbCRLF)
vbDir.append("<img src=""" & GetFolderImg("up") & """ alt=""Up one level"" /></a></td>" & vbCRLF)
vbDir.append("<td><a href="".."" title=""Up one level"">Up one level</a></td>" & vbCRLF)
vbDir.append("</tr></table
' subfolders
for each f in fld.subfolders
if CanViewFile(f) then
vbDir.append("<table class=""tiled""><tr>" & vbCRLF)
vbDir.append("<td class=""icon""><a href=""" & CleanURL(f.name) & """ title=""Folder"">" & vbCRLF)
vbDir.append("<img src=""" & GetFolderImg("closed") & """ alt=""Folder"" /></a></td>" & vbCRLF)
vbDir.append("<td><a href=""" & CleanURL(f.name) & """ title=""Folder"">" & f.name & "</a></td>" & vbCRLF)
vbDir.append("</tr></table
iFolderCount = iFolderCount + 1
iTotalFolderSize = iTotalFolderSize + f.size
end if
next
' files
for each f in fld.files
if CanViewFile(f) then
vbDir.append("<table class=""tiled""><tr>" & vbCRLF)
vbDir.append("<td class=""icon""><a href=""" & CleanURL(f.name) & """ title=""" & f.type & """>" & vbCRLF)
vbDir.append("<img src=""" & GetExtImg(f.name) & """ alt=""" & f.type & """ /></a></td>" & vbCRLF)
vbDir.append("<td><a href=""" & CleanURL(f.name) & """ title=""" & f.type & """>" & f.Name & "</a><br />")
vbDir.append("<span class=""small"">" & FormatFileSize(f.size) & "</span></td>" & vbCRLF)
vbDir.append("</tr></table
iFileCount = iFileCount + 1
iTotalFileSize = iTotalFileSize + f.size
end if
next
response.write vbDir.tostring()
'---------------
'-detailed view-
'---------------
case "details"
' table header
vbDir.append("<table cellspacing=""0"" id=""details-table"">" & vbCRLF)
vbDir.append("<colgroup><c
vbDir.append("<thead id=""header"">" & vbCRLF)
vbDir.append("<tr>" & vbCRLF)
vbDir.append("<th> </
vbDir.append("<th onclick=""sortTables(1)"">
vbDir.append("<th onclick=""sortTables(2)"">
vbDir.append("<th onclick=""sortTables(3)"">
vbDir.append("<th onclick=""sortTables(4)"">
vbDir.append("</tr>" & vbCRLF)
' the "up one level" link
vbDir.append("<tr class=""tc"">" & vbCRLF)
vbDir.append("<td><a href="".."" title=""Up one level"">" & vbCRLF)
vbDir.append("<img src=""" & GetFolderImg("up") & """ alt=""Up one level"" /></a></td>" & vbCRLF)
vbDir.append("<td><a href="".."" title=""Up one level"">..</a></td>" & vbCRLF)
vbDir.append("<td> </
vbDir.append("<td>Up one level</td>" & vbCRLF)
vbDir.append("<td> </
vbDir.append("</tr></thead
' subfolders
vbDir.append("<tbody id=""subfolders"">" & vbCRLF)
for each f in fld.subfolders
if CanViewFile(f) then
vbDir.append("<tr class=""" & sBG & """>" & vbCRLF)
vbDir.append("<td><a href=""" & CleanURL(f.name) & """ title=""Folder"">" & vbCRLF)
vbDir.append("<img src=""" & GetFolderImg("closed") & """ alt=""" & f.type & """ /></a></td>" & vbCRLF)
vbDir.append("<td><a href=""" & CleanURL(f.name) & """ title=""Folder"">" & f.name & "</a></td>" & vbCRLF)
vbDir.append("<td>" & FormatFileSize(f.size) & "</td>" & vbCRLF)
vbDir.append("<td>" & f.type & "</td>" & vbCRLF)
vbDir.append("<td>" & f.DateLastModified & "</td>" & vbCRLF)
vbDir.append("</tr>" & vbCRLF)
SwapBG
iFolderCount = iFolderCount + 1
iTotalFolderSize = iTotalFolderSize + f.size
end if
next
vbDir.append("</tbody>" & vbCRLF)
'files
vbDir.append("<tbody id=""files"">" & vbCRLF)
for each f in fld.files
if CanViewFile(f) then
vbDir.append("<tr class=""" & sBG & """>" & vbCRLF)
vbDir.append("<td><a href=""" & CleanURL(f.name) & """ title=""" & f.type & """>" & vbCRLF)
vbDir.append("<img src=""" & GetExtImg(f.name) & """ alt=""" & f.type & """ /></a></td>" & vbCRLF)
vbDir.append("<td><a href=""" & CleanURL(f.Name) & """ title=""" & f.type & """>" & f.name & "</a></td>" & vbCRLF)
vbDir.append("<td>" & FormatFileSize(f.size) & "</td>" & vbCRLF)
vbDir.append("<td>" & f.type & "</td>" & vbCRLF)
vbDir.append("<td>" & f.datelastmodified & "</td>" & vbCRLF)
vbDir.append("</tr>" & vbCRLF)
SwapBG
iFileCount = iFileCount + 1
iTotalFileSize = iTotalFileSize + f.size
end if
next
vbDir.append("</tbody>" & vbCRLF)
vbDir.append("</table>" & vbCRLF)
response.write vbDir.tostring()
'-----------
'-tree view-
'-----------
case "tree"
sListPath = sDomain
' the root folder
vbDir.append("<ul><li class=""p""><a href=""" & CleanURL(sListPath) & """ title=""" & sListPath & """>" & vbCRLF)
vbDir.append("<img src=""" & GetFolderImg("up") & """ alt="""" /> " & sListPath & "</a></li>" & vbCRLF)
vbDir.append("<li class=""i"">" & vbCRLF)
' path to the current folder
dim path, i
path = split(sCurrentDir, "/")
for i = 1 to ubound(path) - 1
sListPath = sListPath & "/" & path(i)
vbDir.append("<ul><li class=""p""><a href=""" & CleanURL(sListPath) & """ title=""" & sListPath & """>" & vbCRLF)
vbDir.append("<img src=""" & GetFolderImg("open") & """ alt="""" /> " & path(i) & "</a></li><li class=""i"">" & vbCRLF)
next
' subfolders
vbDir.append("<ul>" & vbCRLF)
for each f in fld.subfolders
if CanViewFile(f) then
vbDir.append("<li class=""c""><a href=""" & CleanURL(f.name) & """ title=""" & f.name & """>" & vbCRLF)
vbDir.append("<img src=""" & GetFolderImg("closed") & """ alt=""" & f.type & """ /> " & vbCRLF)
vbDir.append(f.name & "</a></li>" & vbCRLF)
iFolderCount = iFolderCount + 1
iTotalFolderSize = iTotalFolderSize + f.size
end if
next
' files
for each f in fld.files
if CanViewFile(f) then
vbDir.append("<li><a href=""" & CleanURL(f.name) & """ title=""" & f.name & """>" & vbCRLF)
vbDir.append("<img src=""" & GetExtImg(f.name) & """ alt=""" & f.type & """ /> " & vbCRLF)
vbDir.append(f.name & "</a></li>" & vbCRLF)
iFileCount = iFileCount + 1
iTotalFileSize = iTotalFileSize + f.size
end if
next
' close all those lists correctly
vbDir.append("</ul>" & vbCRLF)
for i = 1 to ubound(path)
vbDir.append("</li></ul>" & vbCRLF)
next
response.write vbDir.tostring()
'----------------
'-thumbnail view-
'----------------
case "thumbs"
' the "up one level" icon
vbDir.append("<table class=""thumb""><tr>" & vbCRLF)
vbDir.append("<td class=""icon""><a href="".."" title=""Up one level"">" & vbCRLF)
vbDir.append("<img src=""" & GetFolderImg("up") & """ alt=""Up one level"" /></a></td></tr>" & vbCRLF)
vbDir.append("<tr><td><a href="".."" title=""Up one level"">Up one level</a></td>" & vbCRLF)
vbDir.append("</tr></table
' subfolders
for each f in fld.subfolders
if CanViewFile(f) then
vbDir.append("<table class=""thumb""><tr>" & vbCRLF)
vbDir.append("<td class=""icon""><a href=""" & CleanURL(f.name) & """ title=""Folder"">" & vbCRLF)
vbDir.append("<img src=""" & GetFolderImg("closed") & """ alt=""Folder"" /></a></td></tr>" & vbCRLF)
vbDir.append("<tr><td><a href=""" & CleanURL(f.name) & """ title=""Folder"">")
if len(f.name) > 12 then
vbDir.append(left(f.name, 12) & "...")
else
vbDir.append(f.name)
end if
vbDir.append("</a></td>" & vbCRLF)
vbDir.append("</tr></table
iFolderCount = iFolderCount + 1
iTotalFolderSize = iTotalFolderSize + f.size
end if
next
' files
for each f in fld.files
if CanViewFile(f) then
vbDir.append("<table class=""thumb""><tr>" & vbCRLF)
vbDir.append("<td class=""icon""><a href=""" & CleanURL(f.name) & """ title=""" & f.type & """>" & vbCRLF)
if IsImageFile(f.name) then
if bUseDotNetThumbs then
vbDir.append("<img src=""" & sDomain & sInstDir & "/getimage.aspx?img=" & sCurrentDir &_
CleanURL(f.name) & "&w=" & iThumbWidth & """ alt=""" & f.type & """ />")
else
vbDir.append("<img src=""" & CleanURL(f.name) & """ alt=""" & f.type & """ class=""thumbnail"" />")
end if
else
vbDir.append("<img src=""" & GetExtImg(f.Name) & """ alt=""" & f.type & """ />")
end if
vbDir.append("</a></td></t
vbDir.append("<tr><td><a href=""" & CleanURL(f.name) & """ title=""" & f.type & """>")
if len(f.name) > 12 then
vbDir.append(left(f.name, 12) & "...")
else
vbDir.append(f.name)
end if
vbDir.append("</a></td>" & vbCRLF)
vbDir.append("</tr></table
iFileCount = iFileCount + 1
iTotalFileSize = iTotalFileSize + f.size
end if
next
response.write vbDir.tostring()
end select
%>
<table cellspacing="0" class="footer">
<tr>
<th>
<img src="<%=sDomain & sInstDir%>/icons/folder_cl
<strong><%=iFolderCount%><
<img src="<%=sDomain & sInstDir%>/icons/folder_cl
<strong><%=FormatFileSize(
<img src="<%=sDomain & sInstDir%>/icons/file_blan
<strong><%=iFileCount%></s
<img src="<%=sDomain & sInstDir%>/icons/file_blan
<strong><%=FormatFileSize(
</th>
</tr>
<tr>
<th>
<a href="<%=sDomain & sInstDir%>/setcookie.asp?v
<img src="<%=sDomain & sInstDir%>/images/view_tre
</a>
<a href="<%=sDomain & sInstDir%>/setcookie.asp?v
<img src="<%=sDomain & sInstDir%>/images/view_det
</a>
<a href="<%=sDomain & sInstDir%>/setcookie.asp?v
<img src="<%=sDomain & sInstDir%>/images/view_til
</a>
<a href="<%=sDomain & sInstDir%>/setcookie.asp?v
<img src="<%=sDomain & sInstDir%>/images/view_thu
</a>
</th>
</tr>
</table>
<div class="debug">
<br />
<%
if bDebugMode then
if bSoftWing then
debug = FormatNumber((objProfiler.
set objProfiler = nothing
else
debug = FormatNumber((timer - dDebugTimer), 8, -1, 0, 0)
end if
response.write "Seconds to generate: [" & debug & "]<br />"
end if
%>
<strong><a class="debug" href="http://nscripts.havocaos.com" title="Wumpus" rel="external">Wumpus v1.1</a></strong> - © 2005
<a class="debug" href="mailto:indrek.haav@g
<!-- #include file="footer.html" -->
</div>
</body>
</html>
<%
' clean up
set fld = nothing
set fs = nothing
set vbDir = nothing
set objProfiler = nothing
%>
<%
function GetFileExt(byref filename)
' Returns the file extension for a given filename
if instr(filename, ".") > 0 then
GetFileExt = lcase(right( filename, len(filename) - instrrev(filename, ".") ))
else
GetFileExt = ""
end if
end function
function GetExtImg(byref filename)
' Returns the file icon for a given file extension
dim sResult, sExt
sExt = GetFileExt(filename)
select case sExt
' text files
case "txt", "css", "log", "ini"
sResult = "txt"
' scripts
case "asp", "php", "pl", "plx", "cgi", "aspx", "asa", "js", "xml"
sResult = "asp"
case "java", "jsp"
sResult = "java"
' html
case "htm", "html", "shtml"
sResult = "html"
' office documents
case "doc", "rtf"
sResult = "doc"
case "xls"
sResult = "xls"
case "ppt"
sResult = "ppt"
case "mdb"
sResult = "mdb"
' binaries
case "exe", "msi"
sResult = "exe"
case "dll"
sResult = "dll"
' disk images
case "iso", "img", "bin"
sResult = "iso"
' executables
case "bat", "class"
sResult = "bat"
' archives
case "zip", "rar", "ace", "jar", "tar"
sResult = "zip"
' images
case "gif"
sResult = "gif"
case "tif", "jpg", "jpeg", "bmp"
sResult = "jpg"
case "png", "psd"
sResult = "png"
case "pdf"
sResult = "pdf"
' flash
case "swf", "fla"
sResult = "flash"
' video
case "avi", "mpeg", "mpg"
sResult = "avi"
case "mov"
sResult = "mov"
' audio
case "mp3", "mp4", "wav", "ogg", "aac", "au", "aiff"
sResult = "mp3"
' windows media
case "wmv", "wma", "asf", "wmf"
sResult = "wmv"
' blank
case "blank", ""
sResult = "blank"
' others
case else
sResult = "foo"
end select
GetExtImg = sDomain & sInstDir & "/icons/file_" & sResult & GetIconSize() & ".png"
end function
function GetFolderImg(byref fld)
' Returns the folder icon
GetFolderImg = sDomain & sInstDir & "/icons/folder_" & fld & GetIconSize() & ".png"
end function
function GetIconSize()
' Returns the icon size - 16, 32 or 48 pixels - based on the currently active view mode
if view = "thumbs" then
GetIconSize = "_48"
elseif view = "tiles" then
GetIconSize = "_32"
else
GetIconSize = "_16"
end if
end function
function FormatFileSize(byref filesize)
' Formats the file size
if filesize > 1073741824 then
FormatFileSize = FormatNumber((filesize / 1073741824), 2, -1, 0, 0) & " GB"
elseif filesize > 1048576 then
FormatFileSize = FormatNumber((filesize / 1048376), 2, -1, 0, 0) & " MB"
elseif filesize > 1024 then
FormatFileSize = FormatNumber((filesize / 1024), 2, -1, 0, 0) & " KB"
else
FormatFileSize = filesize & " bytes"
end if
end function
sub SwapBG()
' Toggles the row background for detailed view
if sBG = "tc" then
sBG = "tc2"
else
sBG = "tc"
end if
end sub
function CleanURL(byref sURL)
sURL = replace(sURL, " ", "%20")
sURL = replace(sURL, "&", "&")
CleanURL = sURL
end function
function CanViewFile(byref f)
' Determines whether or not the current file or folder can be viewed
CanViewFile = true
' should we show hidden and system files?
if (f.attributes AND 2) and not bShowHidden then CanViewFile = false
if (f.attributes AND 4) and not bShowSystem then CanViewFile = false
' is the file extension blocked?
if instr(sIgnoreExt, GetFileExt(f.name)) > 0 and f.type <> "File Folder" then CanViewFile = false
' hide index documents?
if (f.name = "default.asp" or f.name = "index.asp") and bHideIndexDoc then CanViewFile = false
end function
function IsImageFile(byref filename)
' Decides whether or not the current file is an image
' Image files get their thumbnail rendered in thumbs view
select case GetFileExt(filename)
case "jpg", "jpeg", "gif", "bmp", "png"
IsImageFile = true
case else
IsImageFile = false
end select
end function
%>
sCurrentDir = split(request.servervariab les("QUERY _STRING"), ";")(1)
First thing I do when I see that is question the (1) on the end. You're calling the split() function, then have that extra set of brakets stuck in there.
If that doesn't do it, you may be attempting to split on a character that isn't present. So do an:
if inStr(request.servervariab les("QUERY _STRING"), ";") then
sCurrentDir = split(request.servervariab les("QUERY _STRING"), ";")
end if
First thing I do when I see that is question the (1) on the end. You're calling the split() function, then have that extra set of brakets stuck in there.
If that doesn't do it, you may be attempting to split on a character that isn't present. So do an:
if inStr(request.servervariab
sCurrentDir = split(request.servervariab
end if
ASKER
If I remove the (1) I get a Type mismatch; If I use the IF statement I get
Server.MapPath() error 'ASP 0171 : 80004005'
Missing Path
/wumpus/index.asp, line 51
Server.MapPath() error 'ASP 0171 : 80004005'
Missing Path
/wumpus/index.asp, line 51
What does the query string actually look like on that page? What is the URL of the page the error comes up on?
ASKER
the url is http://thekesselteam.no-ip.com The query string looks like what you see above.
Do you have actual access to the server your hosting this on? As the best was for Wumpus to work is to change the 403;14 Custom error message to point to /index.asp or whatever page your going to call it.
Doing it this way you must set the following in the config.asp
' run as error doc (403.14) or index doc?
sRunMode = "error"
If you cant get access to the server, you can set it to:
' run as error doc (403.14) or index doc?
sRunMode = "index"
Which will make it run differently.
Anyway, I've recently developed a File Browser script anyway, download it here:
http://www.blandyuk.co.uk/file-browser.zip
I'm sure you can customise it to your requirements :)
Doing it this way you must set the following in the config.asp
' run as error doc (403.14) or index doc?
sRunMode = "error"
If you cant get access to the server, you can set it to:
' run as error doc (403.14) or index doc?
sRunMode = "index"
Which will make it run differently.
Anyway, I've recently developed a File Browser script anyway, download it here:
http://www.blandyuk.co.uk/file-browser.zip
I'm sure you can customise it to your requirements :)
ASKER
I am trying your script and finding it very easy to install.
Obviously you'll have to secure it up as it currently give total access to anything on any Drive as long as the IUSR, (Anonymous Web Access), account has access.
ASKER
I have one question regarding this new script... Instead of downloading, how can I use the link to add that file's name to a text box?
thanks,
stingerman_1
thanks,
stingerman_1
Please re-download the zip again, I've updated it with the functionality you require ;)
Simply adds the filename to the textbox at the top.
Simply adds the filename to the textbox at the top.
ASKER
Thank you sooo much for your help! I will give this a shot and post back..
ASKER
Without being too much of a pain, how could I then take that page and then limit the directory to 1 particular folder on 1 drive? I think this is an awesome script!
thanks a million,
stingerman_1
thanks a million,
stingerman_1
In the script, find these variables:
sPath = Request.QueryString("d")
sFile = Request.QueryString("f")
If you set them to a specific path, the user wont be able to go anywhere apart from what you specify. e.g.
sPath = "C:\my stuff\"
sFile = ""
I'd set sFile = "" as its a security risk. Someone could manually specify ?f=C:\... etc and download anything ;)
Only problem is they will be locked in that directory and wont be able to navigate anywhere. Quick way to get round this is to check sPath:
sPath = Request.QueryString("d")
If InStr(1, sPath, "C:\my stuff\", 1) = 0 Then sPath = "C:\my stuff\"
Just defaults them back to the home directory.
sPath = Request.QueryString("d")
sFile = Request.QueryString("f")
If you set them to a specific path, the user wont be able to go anywhere apart from what you specify. e.g.
sPath = "C:\my stuff\"
sFile = ""
I'd set sFile = "" as its a security risk. Someone could manually specify ?f=C:\... etc and download anything ;)
Only problem is they will be locked in that directory and wont be able to navigate anywhere. Quick way to get round this is to check sPath:
sPath = Request.QueryString("d")
If InStr(1, sPath, "C:\my stuff\", 1) = 0 Then sPath = "C:\my stuff\"
Just defaults them back to the home directory.
ASKER
I'm getting a javascript syntax error when I click on a file.
Strange! Works fine here. Have you modified it in any way to cause this error?
ASKER
When I put in in place I did not modify the code other than adding a link in the action attribute of the form element.
By the way, I am really enjoying this script! Do you have any others?
thanks,
Stingerman_1
By the way, I am really enjoying this script! Do you have any others?
thanks,
Stingerman_1
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I will. Thanks again for your work!
No problem :)
http://www.w3schools.com/asp/asp_ref_filesystem.asp