ARIFUL ISLAM
ARIFUL ISLAM

Reputation:

How can access the root directory of a folder

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.

Upvotes: 2

Views: 5942

Answers (3)

Petrunov
Petrunov

Reputation: 774

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/';

Upvotes: 3

duckyflip
duckyflip

Reputation: 16499

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');

Upvotes: 5

fluf
fluf

Reputation: 1265

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

Upvotes: 0

Related Questions