AriesTiger
AriesTiger

Reputation: 69

PHP: Include with template system

I have files listed at /home/Discussions/include/ want to contain within my guide library at /home/Library/index.php. How do I go about doing this?

This is the current code I have:

<?php
define('path_var', dirname(__FILE__).'/../Discsusions');
require path_var.'/include/common.php';
include path_var.'/include/header.php';
?>

I've tried many different variations and such and I just can't seem to fix this issue.

Update: My directory structure is thus:

/home/index.php (splash page)
/home/Discussions/index.php (talk page)
/home/Library/index.php (hopeful new guides page)

Upvotes: 0

Views: 48

Answers (1)

Marc B
Marc B

Reputation: 360572

__FILE__ is the absolute path to the current script. so given your script path of

/home/Library/index.php

then

dirname(__FILE__) -> /home/Library

and

dirname(__FILE__) .'/../Discsusions' -> /home/Library/../Discussions

which is equivalent to

/home/Discussions

So, path_var = /home/Discussions. So your include calls are going to be:

require path_var.'/include/common.php';
require '/home/Discussions/include/common.php';

So your code SHOULD be working. Are you sure that your script has the rights to read things from both directories?

Upvotes: 1

Related Questions