Pergunta

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

Foi útil?

Solução

define('ROOT', realpath(dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR));

you can use

__FILE__

Outras dicas

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

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

dirname(__FILE__)

Try this one:

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

This should get the absolute path of the current directory.

You can get the absolute path with this:

$dirpath=realpath(dirname($_SERVER['PHP_SELF']));
echo getcwd();

Should also do the trick.

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

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top