[英]Getting path from current working directory not from root
Hello everyone I am trying to get the path from the current working directory but I don't want the root path included with it in PHP or wordpress. 大家好,我正在尝试从当前工作目录获取路径,但是我不希望PHP或wordpress中包含根路径。 For example I have a directory structure like this.
例如,我有一个像这样的目录结构。
-C
--wamp64
--------www
-----------project
------------------Other directories
Now, what exactly I want is to get the path from project directory something like this. 现在,我真正想要的是从项目目录获取类似这样的路径。
-project
--Other directories
Currently with __DIR__
or dirname(__FILE__)
I am getting. 目前正在使用
__DIR__
或dirname(__FILE__)
。
C:\\wamp64\\www\\project\\other_directories
C:\\ wamp64 \\ www \\ project \\ other_directories
But I want to get. 但是我想得到。
\\project\\other_directories
\\ project \\ other_directories
And I wanted to make it dynamic so that it picks up the right path from which ever server I deploy this project. 而且我想使其动态化,以便它从我部署此项目的任何服务器上选择正确的路径。
I searhed alot but couldn't find the solution. 我晒了很多,但找不到解决方案。
https://www.w3schools.com/php/showphp.asp?filename=demo_global_server https://www.w3schools.com/php/showphp.asp?filename=demo_global_server
Check above URL and use $_SERVER['PHP_SELF'];
检查上面的URL,并使用
$_SERVER['PHP_SELF'];
remove the filename from that and you will have the path relative to the document root. 从中删除文件名,您将拥有相对于文档根目录的路径。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.