Reputation: 2996
I have a PHP file that I need it to detect it's directory it's in. In my case I want it to return C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\
I think that this is pretty straightforward but if there is something you don't understand just comment
Upvotes: 3
Views: 649
Reputation: 88796
In addition to the directory the file is in, you may find the directory that corresponds to the web server's /
URI (http://www.example.com/
URL) useful. That's stored in $_SERVER['DOCUMENT_ROOT']
Upvotes: 1
Reputation: 400972
The magic-constant __FILE__
contains the full path to the file in which you write it.
The dirname
function returns the path to the directory corresponding to a file.
So, in your case, to get the path to the directory containing your file, you can use :
echo dirname(__FILE__);
Upvotes: 3