absolute paths

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
RobDraw
Forum Newbie
Posts: 2
Joined: Tue Jun 02, 2009 2:12 pm

absolute paths

Post by RobDraw »

My directory is something like this:

root
../members
../includes
../includes/column
../includes/column/modules

in root i include in the index.php
<?php include "includes/column/right_column.php";?>

the right_column.php also includes various modules like so:
<?php include "includes/column/modules/right_col_yog.php";?>

which basically populate a column on the webpage.

So far this works ok.

My problem is when i want to include the same module/s in a file in the members directory.

I can call
<?php include "../includes/column/right_column.php";?>
Which finds the file "right_column.php", but it dosent find the includes in this file like "right_col_yog.php".

I realise the problem maybe due to using relative path but I am wondering to write absolute paths for this problem and if it is solvable.

Any pointers
User avatar
mikemike
Forum Contributor
Posts: 355
Joined: Sun May 24, 2009 5:37 pm
Location: Chester, UK

Re: absolute paths

Post by mikemike »

Just define a path in a config file with your absolute path in it:

Code: Select all

$include_dir = '/var/www/vhosts/example.com/httpdocs/';
Then use it in all your includes

Code: Select all

include($includes_dir.'includes/modules/columns/right_col.php');
..or just add it into your include dir's in your php.ini
RobDraw
Forum Newbie
Posts: 2
Joined: Tue Jun 02, 2009 2:12 pm

Re: absolute paths

Post by RobDraw »

Thank You.
Post Reply