Reputation: 939
i am new in php. here i have given my project structure and my working folder name is 'Bookings'.
-Bookings
+Class
+lib
-Public
-application
+controller
+css
+images
+frontend
when i used $_SERVER['DOCUMENT_ROOT'] like this :
$path = $_SERVER['DOCUMENT_ROOT'];
echo $path;
so obtain output is
D:/xampp/htdocs
so how to get this path "D:/xampp/htdocs/Bookings" in php?
Thanks
Upvotes: 4
Views: 16024
Reputation: 22428
You can get the absolute path with this:
$dirpath=realpath(dirname($_SERVER['PHP_SELF']));
Upvotes: 0
Reputation: 8770
Try this one:
$dir = realpath('./');
echo $dir;
This should get the absolute path of the current directory.
Upvotes: 0
Reputation: 1315
echo getcwd();
Should also do the trick.
That's where the script starts. You may want to add directories upon it.
Upvotes: -1
Reputation: 89
If you want from the same file you can use this function.
dirname(__FILE__)
Upvotes: 0
Reputation: 4558
With
__DIR__
( http://php.net/manual/en/language.constants.predefined.php )
Upvotes: 0
Reputation: 1866
define('ROOT', realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR));
you can use
__FILE__
Upvotes: 3
Reputation: 13166
You can use dirname($_SERVER['SCRIPT_FILENAME']);
to get your current directory for your existing file.
Upvotes: 3