我试图在php中返回文件的当前目录,无论它在浏览器栏中显示什么。我试过了:
echo $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
如果网址是
http://example.com/directory1/directory2/var1/var2/var3
上面的代码返回
example.com/directory1/directory2/var1/var2/var3
即使var1 / var2 / var3是由htaccess RewriteRule驯服的GET_[]
个变量。有没有一个体面的方式来获取目录?在上面的情况下,我想回来:
example.com/directory1/directory2/
感谢。
答案 0 :(得分:6)
如何用SCRIPT_FILENAME
替换它?
str_replace($_SERVER['DOCUMENT_ROOT'], '', dirname($_SERVER['SCRIPT_FILENAME']));