高分求救:如何将绝对路径转华为服务器的虚拟路径?

josserchai 2002-06-21 12:26:53
我己知道绝对路径为:
E:\web\library\bookfile\out.asp
那么我如何将它转化为
http://xxx.xxx.xxx.xx/bookfile/out.asp
这种形式的虚拟路径呢?

其中需要最主要的是如何测知out.asp在
服务器上的虚拟路径(即如何测知/library是out.asp的虚拟路径)?
请问如何做?请给出代码.一定给分.
多谢!



...全文
86 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
julyclyde 2002-06-21
  • 打赏
  • 举报
回复
cannot
MeXP 2002-06-21
  • 打赏
  • 举报
回复
http://www.csdn.net/expert/topic/813/813198.xml?temp=.6079218
julyclyde 2002-06-21
  • 打赏
  • 举报
回复
哦。那你如果对一个不在虚拟目录范围内的文件操作,用你们大家的方法也统同样可以得到结果。嘻嘻
xingworld 2002-06-21
  • 打赏
  • 举报
回复
不好意思,刚刚上了趟厕所,所以耽误了点时间,源代码如下:




out.asp
-----------------------------------------------------------------
<%
ServName = Request.ServerVariables( "SERVER_NAME" ) '服务器虚拟地址
ScrName = Request.ServerVariables( "SCRIPT_NAME" ) '所在文件虚拟路径

T_ScrName = Server.MapPath(ScrName) '所在文件绝对路径


response.write "<br>1 <b>T_ScrName=</b>" & T_ScrName & " ____所在文件绝对路径"

response.write "<br>2 <b>ScrName=</b>" & ScrName


'下面的代码太笨拙,但是我忘了那个可以直接获取当前正在执行文件的参数,所以下面就要麻烦一些。
'------------------------------------------------------------------------
if left(ScrName,1)="/" then ScrName=right(ScrName,len(ScrName)-1)
ArrScrName=split(ScrName,"/")
for i=0 to Ubound(ArrScrName)-1
N_ScrName=N_ScrName & "/" & ArrScrName(i)
next
response.write "<br>2 <b>你所要的虚拟路径:</b>" & N_ScrName
'------------------------------------------------------------------------


response.write "<br>3 <b>ServName=</b>" & ServName & " ____服务器名"

response.write "<br>4 <b>ServName + ScrName=</b>" & ServName & ScrName

response.write "<br>5 <b>http:// + ServName + ScrName=</b>http://" & ServName & ScrName
%>
Iamfish 2002-06-21
  • 打赏
  • 举报
回复
其中需要最主要的是如何测知out.asp在
服务器上的虚拟路径(即如何测知/library是out.asp的虚拟路径)?
请问如何做?请给出代码.一定给分.
___________________________________________________-

server.mappath("/")
得到根目录在服务器上的目录。
server.mappath(WebDirOrFile)
返回WebDirOrFile在服务器上的绝对路径.
Iamfish 2002-06-21
  • 打赏
  • 举报
回复
对了,还要把"\"换成"/"
Iamfish 2002-06-21
  • 打赏
  • 举报
回复
能!

p="E:\web\library\bookfile\out.asp"
l=len(server.mappath("/"))
h="http://xxx.xxx.xxx.xx/"
url=h & mid(h,l)

试试,可能mid会算错一个字符,我要去吃了,等一下帮你试。

28,391

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧