tags:

views:

96

answers:

3

recently i worked in a project. the project has one root directory named "Project".the "Project" directory has also two sub-directory named "project_a" and "project_b". the "project_b" directory has two more sub-directory named "project_b_1" and "project_b_2". when i am on a page which is contains "project_b_2" directory then how can i access a file which is exists in the "project_a" directory. all code must be php code.

A: 

You should be able to go up in the directory tree :

#when you are in project/project_b/project_b_2
$dir = "../../project_a";

That is the way I usually follow, although you can use

$_SERVER["SITE_HTMLROOT"]

which should take you to the root of the website

fluf
+4  A: 

Using $_SERVER['DOCUMENT_ROOT'] will always reference to where the root is in your defined site/vhost etc.
So using something like this should work:

fopen($_SERVER['DOCUMENT_ROOT'].'/projectA/subfileB.html');
duckyflip
+2  A: 

Find the path to 'project_a' relative to script in 'project_b_2':

$path = realpath( dirname( __FILE __ ) . '/../../project_a/' );

Find the path to 'project_a' relative to the webroot:

$path = $_SERVER['DOCUMENT_ROOT'] . '/Project/project_a/';
Petrunov