php getcwd() - exclude server directories

460 Views Asked by At

I have the following line of code which works on my local machine because the root directory of the server is the same as the root directory of the site.

$directories = explode("/", str_replace($_SERVER['DOCUMENT_ROOT'] . "/", "",  getcwd()));

How can I adapt this to work on my remove server where the root directory is several levels below that of the site. I guess I need to only include the site directories rather than the server directories.

1

There are 1 best solutions below

0
On

My logic states you need to put your remote server address here:

$directories = explode("/here/", str_replace($_SERVER['DOCUMENT_ROOT'] . "/", "",  getcwd()));

If that doesn't work, check these threads out, I think your solution is in one of them

SO Thread: Root path doesn't work with php include

Tech-Recipes-Thread: PHP: determine the directory path of the server root