How to determine the directory where the php file is located

I have a PHP file that I need to find it in a directory. In my case, I want it to returnC:\Program Files\Apache Software Foundation\Apache2.2\htdocs\

I think it’s pretty simple, but if there is something you don’t understand just a comment

+3
source share
3 answers

In PHP 5.3: __DIR__

In the lower version: dirname(__FILE__)

+11
source

The magic constant contains the full path to the file in which you write it. __FILE__

The function returns the path to the directory corresponding to the file. dirname

So, in your case, to get the path to the directory containing your file, you can use:

echo dirname(__FILE__);
+3
source

, , , - / URI (http://www.example.com/ URL). $_SERVER['DOCUMENT_ROOT']

+1

Source: https://habr.com/ru/post/1739641/


All Articles