I am trying to return the current directory of a file in php, regardless what it says in the browser bar. I have tried:
echo $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
If the url is
http://example.com/directory1/directory2/var1/var2/var3
the above code returns
example.com/directory1/directory2/var1/var2/var3
even though var1/var2/var3 are GET_[]
variables tamed by a htaccess RewriteRule. Is there a decent way to get the directory? in the case above I would like to return:
example.com/directory1/directory2/
thanks.
How about replace it with SCRIPT_FILENAME
?
str_replace($_SERVER['DOCUMENT_ROOT'], '', dirname($_SERVER['SCRIPT_FILENAME']));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With