| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 988 人关注过本帖
标题:[求助]有关虚拟路径的修改?
只看楼主 加入收藏
d120899569
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2006-3-21
收藏
 问题点数:0 回复次数:12 
[求助]有关虚拟路径的修改?
<%
'创建FileSystemObject对象
Set fso = Server.CreateObject("Scripting.FileSystemObject")
'获得路径
Path=request.querystring("Path") '"class/"
If Right(Path,1)="/" AND Path<>"/" Then Path=Left(Path,Len(Path)-1)
response.write("<font color='white'><b>" & Path & "</font></b><br>")
Var =InstrRev(Path,"/")
dirup=left(Path,Var)
'显示上一级目录链接
response.write ("[<a href='browser.asp?path=" & dirup & "'>上一级</a>]")
%>



上面这个代码大概是获得服务器根目录下的所有文件等,但是现在我想改成获得根目录下的test这个文件夹中的所有文件信息等用来保护根目录下的一些文件.


我试过将"/"更改成"../test/"或者"test/";也试过将Path=request.querystring("Path") 更改成Path="test/" ,但是全都失败了.
前者是不起作用,后者虽然获得了TEST文件夹中的信息但是无法后退或者进入TEST里面的子目录并且无法上传文件.


恳请高手指点一下我该怎么修改?? 谢谢!!!
搜索更多相关主题的帖子: Path 路径 Var response 
2006-03-21 20:11
d120899569
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2006-3-21
收藏
得分:0 
差点忘了下面还有处

'获取用户选择的功能选项
aktion=request.querystring("aktion")
Set ts=fso.GetFolder(Server.MapPath(Path))


请高手指点我下如何才能完成那个功能.
2006-03-21 20:47
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
收藏
得分:0 
Set ts=fso.GetFolder(Server.MapPath("test/"))
直接获取呢绕过上面的代码?
2006-03-21 21:08
d120899569
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2006-3-21
收藏
得分:0 
以下是引用yms123在2006-3-21 21:08:00的发言:
Set ts=fso.GetFolder(Server.MapPath("test/"))
直接获取呢绕过上面的代码?



运行结果如下:

  • 错误类型:
    Microsoft VBScript 运行时错误 (0x800A004C)
    路径未找到
    /test/browser.asp, 第 61 行

  • 浏览器类型:
    Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; TencentTraveler ; .NET CLR 1.1.4322)
  • [此贴子已经被作者于2006-3-21 22:05:27编辑过]

    2006-03-21 22:05
    d120899569
    Rank: 1
    等 级:新手上路
    帖 子:9
    专家分:0
    注 册:2006-3-21
    收藏
    得分:0 
    我将"test/"改成"../test/",虽然可以显示TEST文件夹里面的内容了但是在想进入里面的子目录就不行了,单击子目录仍然显示的是TEST里面的内容.


    修改成"/test/"和上面一个情况.
    2006-03-21 22:09
    d120899569
    Rank: 1
    等 级:新手上路
    帖 子:9
    专家分:0
    注 册:2006-3-21
    收藏
    得分:0 

    <%@ Language=VBScript %>
    <%Response.buffer=true
    Level=1
    Select Case request.querystring("aktion")
    Case "createfolder" '创建子目录
    Level=2
    Case "createfile" '创建文件
    Level=2
    Case "deletefile" '删除文件
    Level=2
    Case "deletefolder" '删除目录
    Level=2
    End Select
    %>
    <!--#include File ="includes/check.inc"-->
    <HTML>
    <HEAD>
    <meta http-equiv="content-type" content="10;charset=gb2312">
    <title>aspEdit</title>
    <link rel=stylesheet type="text/css" href="styles/style.css">
    </HEAD>


    <BODY><!--#include File ="includes/banner.inc"-->
    <div align="center">
    <%
    '创建FileSystemObject对象
    Set fso = Server.CreateObject("Scripting.FileSystemObject")
    '获得路径
    Path=request.querystring("Path") '"class/"
    If Right(Path,1)="/" AND Path<>"/" Then Path=Left(Path,Len(Path)-1)
    response.write("<font color='white'><b>" & Path & "</font></b><br>")
    Var =InstrRev(Path,"/")
    dirup=left(Path,Var)
    '显示上一级目录链接
    response.write ("[<a href='browser.asp?path=" & dirup & "'>上一级</a>]")
    %>
    [<a href="browser.asp?path=/">根目录</a>]<br>
    <table border="0" cellpadding="0" cellspacing="0" width="100%">
    <tr>
    <td>
    <form name="FormName" <%="action='browser.asp?path=" & path & "&aktion=createfolder'"%>method="post">
    <div align="center">
    <input type="text" name="newSubF" size="24"><br>
    <input type="submit" name="submitButtonName" value="创建子目录"></div>
    </form>
    </td>
    <td>
    <form name="FormName" <%="action='browser.asp?path=" & path & "&aktion=createfile'"%>method="post">
    <div align="center">
    <input type="text" name="newFile" size="24"><br>
    <input type="submit" name="submitButtonName" value="创建文件"></div>
    </form>
    </td>
    </tr>
    </table>
    <hr>
    <%
    '获取用户选择的功能选项
    aktion=request.querystring("aktion")
    Set ts=fso.GetFolder(Server.MapPath("/test/"))
    Select Case aktion
    Case "upload" '文件上载
    If Len(Request.TotalBytes) > 0 Then
    Response.Write("文件将被上载到当前目录 " & Path)
    Init '初始化
    For x=1 to int(request.querystring("NumOfUploads"))
    fName="fName" & x
    Server.ScriptTimeout = 250 '由于文件上传速度比较慢,因此要设置页面处理时间要延长
    If getFileName(fName)<>"" then
    If saveAs(fName,"") = true then
    response.write ("<br>文件" & getFileName(fName) & " (Content-Type: " & getContentType(fName) & ") 上载成功.")
    else
    response.write("<br>文件 " & getFileName(fName) & "上载错误!")
    end if
    End if
    Next
    Response.Write("<hr>")
    End If
    Case "deletefile" '删除文件
    fso.DeleteFile(Server.MapPath(request.querystring("file")))
    response.write("文件被删除.<hr>")
    Case "deletefolder" '删除目录
    fso.DeleteFolder(Server.MapPath(request.querystring("folder")))
    response.write("目录被删除.<hr>")
    Case "createfile"
    If right(Path,1)<>"/" then Path= Path & "/"
    fso.CreateTextFile(Server.MapPath(Path & request.form("newFile")))
    response.write("文件被创建成功!.<hr>")
    Case "createfolder" '创建目录
    If right(Path,1)<>"/" then Path= Path & "/"
    fso.CreateFolder(Server.MapPath(Path & request.form("newSubF")))
    response.write("目录创建成功!.<hr>")
    End select

    %>
    <table border="0" cellpadding="0" cellspacing="1" width="100%" bgcolor="#FFFFFF">
    <tr>
    <td colspan="7" bgcolor="#C0C0C0" height="14">
    <div align="center">
    <font color="#FFFFFF">
    <b><span style="background-color: #000000">子目录</span></b></font></div>
    </td>
    </tr>
    <%
    For each SubF in ts.Subfolders '获取所有子目录
    If right(Path,1)="/" then
    WholeSubF=Path & SubF.Name
    else
    WholeSubF=Path & "/" & SubF.Name
    end if%>
    <tr>
    <td colspan="3"><%="<a href='browser.asp?path=" & WholeSubF & "'>" & SubF.Name & "</a>"%></td>
    <td width="15%">
    <div align="right">
    <%Response.Write SubF.DateLastModified%></div>
    </td>
    <td width="5%"></td>
    <td width="5%">
    <div align="center">
    </div>
    </td>
    <td width="5%">
    <div align="center">
    <font size="-2">
    <a <%="href='browser.asp?path=" & path & "&aktion=deletefolder&folder=" & WholeSubF & "'"%>>
    删除</a></font></div>
    </td>
    <%next%>
    </tr>
    <tr>
    <td colspan="7" bgcolor="#C0C0C0">
    <div align="center">
    <b>文件</b></div>
    </td>
    </tr>
    <%
    For each File in ts.files '显示所有文件
    If right(Path,1)="/" then
    WholeFile=Path & File.Name
    else
    WholeFile=Path & "/" & File.Name
    end if

    %>
    <tr>
    <td><%=File.Name%></td>
    <td width="25%">
    <div align="center">
    <%=File.Type%></div>
    </td>
    <td width="5%">
    <div align="right">
    <%
    if File.Size <1024 Then '如果文件小于1K,则直接显示字节数量
    Response.Write File.Size & " B"
    ElseIf File.Size < 1048576 Then '小于1M的显示KB
    Response.Write Round(File.Size / 1024.1) & " KB"
    Else
    Response.Write Round((File.Size/1024)/1024.1) & " MB" '其余显示MB
    End if
    Var=InstrRev(File.Name,".")
    FileType=Right(File.Name,Len(File.Name)-Var)
    %></div>
    </td>
    <td width="15%">
    <div align="right">
    <%Response.Write File.DateLastModified%></div>
    </td>
    <td width="5%">
    <div align="center"></div>
    </td>
    <td width="5%">
    <div align="center">
    <%
    response.write (" <font size='-2'><a href='" & WholeFile & "' target=_blank'>打开/下载</a></font>")
    %></div>
    </td>
    <td width="5%">
    <div align="center">
    <font size="-2">
    <a <%="href='browser.asp?path=" & path & "&aktion=deletefile&file=" & WholeFile & "'"%>>
    删除</a></font></div>
    </td>
    </tr>
    <%next%>

    </table>
    <hr>
    <!--#include File ="file_upload.asp"-->

    <div align="center">
    <%
    '创建FileSystemObject对象
    Set fso = Server.CreateObject("Scripting.FileSystemObject")
    '获得路径
    Path=request.querystring("Path")
    If Right(Path,1)="/" AND Path<>"/" Then Path=Left(Path,Len(Path)-1)
    response.write("<font color='white'><b>" & Path & "</font></b><br>")
    Var =InstrRev(Path,"../")
    dirup=left(Path,Var)
    '显示上一级目录链接
    response.write ("[<a href='browser.asp?path=" & dirup & "'>上一级</a>]")
    %>
    [<a href="browser.asp?path=/">根目录</a>]

    </FORM>

    </div>
    </BODY>
    </HTML>
    <%
    Set fso = Nothing
    Set ts = Nothing
    %>

    2006-03-21 22:13
    d120899569
    Rank: 1
    等 级:新手上路
    帖 子:9
    专家分:0
    注 册:2006-3-21
    收藏
    得分:0 
    上面红色部分就是获取服务器路径的代码.
    2006-03-21 22:14
    d120899569
    Rank: 1
    等 级:新手上路
    帖 子:9
    专家分:0
    注 册:2006-3-21
    收藏
    得分:0 
    请问有没有高手愿意指点我下
    2006-03-22 12:40
    d120899569
    Rank: 1
    等 级:新手上路
    帖 子:9
    专家分:0
    注 册:2006-3-21
    收藏
    得分:0 
    高手们指点我下把,快郁闷死了!
    2006-03-22 19:38
    yms123
    Rank: 16Rank: 16Rank: 16Rank: 16
    等 级:版主
    威 望:209
    帖 子:12488
    专家分:19042
    注 册:2004-7-17
    收藏
    得分:0 
    Set ts=fso.GetFolder(Server.MapPath("/test/"))
    '此方法可以返回某个目录的上一级目录
    Function ShowFileAccessInfo(filespec)
    Dim fso, f, s
    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.GetFile(filespec)
    ShowFileAccessInfo=f.ParentFolder
    End Function

    2006-03-22 22:01
    快速回复:[求助]有关虚拟路径的修改?
    数据加载中...
     
       



    关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

    编程中国 版权所有,并保留所有权利。
    Powered by Discuz, Processed in 0.013159 second(s), 7 queries.
    Copyright©2004-2024, BCCN.NET, All Rights Reserved