Can you include a file that is up and then down a directory?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
yeahyeahyeah
Forum Newbie
Posts: 1
Joined: Mon Jun 25, 2007 2:42 pm

Can you include a file that is up and then down a directory?

Post by yeahyeahyeah »

Can you include a file that is in another directory at the same level?

This example shows FOLDER A as the top folder which contains 2 folders FOLDER 1 and FOLDER 2.

I have some php files (file1.php and file2.php) in FOLDER 1 and would like to include the inculde.php file (which is in FOLDER 2) into file1.php and file2.php.

Is there a way of doing this without using this

Code: Select all

include($_SERVER['DOCUMENT_ROOT'].'FOLDER 1/include.php');
style of include. Can it be done using this style

Code: Select all

include ("../FOLDER 2/include.php");
?

FOLDER A (htdocs)
|
|
-----FOLDER 1
| |
| |------file1.php
| |------file2.php
|
|
-----FOLDER 2
| |
| |------include.php
|
|
|----OTHER FILES
User avatar
guitarlvr
Forum Contributor
Posts: 245
Joined: Wed Mar 21, 2007 10:35 pm

Post by guitarlvr »

it can be done using

Code: Select all

include ('../path/to/file.php');
Wayne
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

Code: Select all

include ("../FOLDER 2/include.php");
Will work. It is better coding style to use include without the brackets though.
Post Reply