?
本文檔使用 PHP中文網(wǎng)手冊 發(fā)布
MapPath 方法可把指定的路徑映射到服務器上相應的物理路徑上。
注意:此方法不能用于 Session.OnEnd 和 Application.OnEnd 中。
Server.MapPath(path)
參數(shù) | 描述 |
---|---|
path | 必需。映射為物理路徑的相對路徑或絕對路徑。如果該參數(shù)以 / 或 \ 開頭,則返回完整的虛擬路徑。如果該參數(shù)不以 / 或 \ 開頭,則返回相對于正在被處理的 .asp 文件的路徑。 |
舉例,文件 test.asp 位于 C:\Inetpub\wwwroot\Script。
文件 Test.asp (位于 C:\Inetpub\wwwroot\Script) 包含下列代碼:
<%
response.write(Server.MapPath("test.html") & "<br>")
response.write(Server.MapPath("script/test.html") & "<br>")
response.write(Server.MapPath("/script/test.html") & "<br>")
response.write(Server.MapPath("script") & "<br>")
response.write(Server.MapPath("/") & "<br>")
response.write(Server.MapPath("") & "<br>")
%>
輸出:
c:inetpubwwwrootscripttest.html
c:inetpubwwwrootscriptscripttest.html
c:inetpubwwwrootscripttest.html
c:inetpubwwwrootscript
c:inetpubwwwroot
c:inetpubwwwroot
如何使用一個相對路徑來返回到達正在瀏覽器中查看的頁面的相對物理路徑:
<%
response.write(Server.MapPath("../"))
%>
或者:
<%
response.write(Server.MapPath(".."))
%>