Shoe
Shoe

Reputation: 76298

Including files

Ok guys, i was wondering: How could i access every file by every file in the same way. I mean, let's say i have this folder & files schema:

A/index.php
A/B/file1.php
A/B/famous.php
A/B/C/file2.php

I'd like to be able to do something like this:

index.php

include('B/famous.php');

file1.php

include('B/famous.php');

file2.php

include('B/famous.php');

How to do that?

Upvotes: 0

Views: 141

Answers (3)

Ian Wetherbee
Ian Wetherbee

Reputation: 6109

Give each root file a variable $root_path = ../; (changed corresponding to the level the script is at, then your include statement will look like include($root_path . "B/famous.php");

Upvotes: 0

Nanne
Nanne

Reputation: 64429

You could include it trough an absolute path. Or make a config file what defines this absolute path, and put it in the root

so you'd do

include('/config.php');
include(BASEPATH.'B/famous.php');

config.php would have something like this in it

define(BASEPATH, "/var/www/myDomain/mySite");

Upvotes: 2

ceejayoz
ceejayoz

Reputation: 180176

Add /path/to/A/B to your PHP installation's php.ini include_path directive.

Upvotes: 1

Related Questions