一个在服务器端选择文件的小程序,在要插入服务器端的文件,例如服务器端已经上传的图片,或者是菜单管理中选择要执行的文件,都是有用的,当然,还可以改作它用,就看你的需要了。
限于时间,没能打它做成像windows的打开文件窗口一样的效果,哪位网友做了,告诉一声啊,迟些我自己抽得出时间也会做的,希望能与大家一起进步。
<%@ language=vbscript codepage="936"%>
<% option explicit %>
<%
function getfilename(strpath)
dim filename
filename = mid(strpath,instrrev(strpath,"\")+1)
getfilename = filename
end function
%>
<html>
<head>
<title>noteless valley(lijun.org)程序示例</title>
<meta name="vs_targetschema" content="http://schemas.microsoft.com/intellisense/ie5">
<meta http-equiv="content-type" content="text/html; charset=gb2312">
<meta name="generator" content="microsoft visual studio.net 7.0">
<style type=text/css>
body
{
font-size: 16px;
border-top-style: none;
font-family: verdana, 宋体;
border-right-style: none;
border-left-style: none;
background-color: white;
border-bottom-style: none;
}
a
{
text-decoration: none;
}
a:hover
{
text-decoration: underline;
}
</style>
<script language=javascript>
function selfile(filename) {
lblmsg.innertext = filename;
}
</script>
</head>
<body>
<%
dim strsvrpath, strcurrentdirectory
strsvrpath = request.querystring("path")
if strsvrpath = "" then
strsvrpath = request.servervariables("script_name")
strsvrpath = mid(strsvrpath,1,instrrev(strsvrpath,"/")) 在这里设定初始目录,此处我设为根目录
end if
strcurrentdirectory = server.mappath(strsvrpath)
response.write "当前目录:" & strsvrpath & "<br>"
dim fso, folder, subfolder, files, item
set fso = server.createobject("scripting.filesystemobject")
set folder = fso.getfolder(strcurrentdirectory)
set subfolder = folder.subfolders
if strsvrpath <> "/" then
response.write "<a href=?path=" & mid(strsvrpath,1,instrrev(mid(strsvrpath,1,len(strsvrpath)-1),"/")) & ">[to parent directory]</a>" & "<br>"
end if
for each item in subfolder
response.write "<a href=?path=" & strsvrpath & getfilename(item) & "/><font face=wingdings>0</font>" & _
getfilename(item) & "</a><br>"
next
set files = folder.files
for each item in files
取绝对路径
response.write "<a href=javascript:selfile(" & strsvrpath & getfilename(item) & _
");><font face=wingdings>3</font>" & getfilename(item) & "</a><br>"
取文件名
response.write "<a href=javascript:selfile(" & getfilename(item) & ");><font face=wingdings>3</font>" & _
getfilename(item) & "</a><br>"
取相对某目录的相对路径,本例为“/myweb/”
response.write "<a href=javascript:selfile(" & replace(strsvrpath,"/myweb/","") & getfilename(item) & ");><font face=wingdings>3</font>" & _
getfilename(item) & "</a><br>"
next
set fso = nothing
%>
<p id=lblmsg></p>
</body>
</html>