4

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

nic
  • 929
  • 3
  • 14
  • 22
  • When people answer your questions, you should use the arrows to the left of their answer to vote it up if it is helpful. If you end up using a particular answer, there is a checkmark that you can click to accept the answer. It's an easy way to pay someone back for taking the time to help you... – phpmeh Jan 25 '12 at 07:44

7 Answers7

3

You can use dirname($_SERVER['SCRIPT_FILENAME']); to get your current directory for your existing file.

Mohammad Saberi
  • 12,864
  • 27
  • 75
  • 127
  • Perfect! This is the only solution that delivers the proper server path. All others outputs on windows xampp windows style path which is usually not what we really want. – Hexodus Jan 05 '16 at 11:29
3
define('ROOT', realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR));

you can use

__FILE__
jackdoe
  • 1,846
  • 1
  • 15
  • 13
0

You can get the absolute path with this:

$dirpath=realpath(dirname($_SERVER['PHP_SELF']));
Jahid
  • 21,542
  • 10
  • 90
  • 108
0

With

__DIR__

( http://php.net/manual/en/language.constants.predefined.php )

romainberger
  • 4,563
  • 2
  • 35
  • 51
0

If you want from the same file you can use this function.

dirname(__FILE__)
Prathab K
  • 89
  • 5
0

Try this one:

   $dir =  realpath('./');
   echo $dir;

This should get the absolute path of the current directory.

jerjer
  • 8,694
  • 30
  • 36
-1
echo getcwd();

Should also do the trick.

That's where the script starts. You may want to add directories upon it.

Jens
  • 1,302
  • 1
  • 13
  • 20
  • Tested and this won't work because this returns the local file path, i.e. `file://`, and xampp will log an error: `Not allowed to load local resource` – Bram Vanroy Nov 08 '15 at 00:01