Folder Structure - PHP Include

AusQB

New Member
I have a PHP-based site set up with a few .php documents which are included as common code (head.php, nav.php, body_top.php. body_bottom.php) in each page.

I want to move a few pages into a sub-folder, meaning the include statements (<?php include('head.php') ?>) no longer point to the right location. Even when appending "../" to the front of the file path, it doesn't load properly since all the paths in the style sheets for instance are relative to the root folder.

Can I specify an absolute path which is relative to the root folder (if that makes sense)? In other words, I want all references to the style sheet to be href="root/css/style.css", so that all files point to the same place regardless of their location in the file structure.

Is there a way in Expression Web to automatically adjust the file path like it does for anchor tags when moving files?
 

AusQB

New Member
Alright, so by changing

PHP:
<?php include('head.php') ?>

to

PHP:
<?php
	$path = $_SERVER['DOCUMENT_ROOT'];
	$path .= "/includes/head.php";
	include_once($path);
?>

I've managed to correctly include the head.php file in pages of different directory levels.

However, that head.php file contains all the links to CSS and script files. If I include it in a page in a sub folder, the references to those files will now be pointing one level too low.

In other words, the CSS sheets only work on the pages in the root folder. I need to be able to dynamically change the paths to the include files as well as the css, script and any other files in the head.php file.

Is that where the config.php file comes in?
 

adx

New Member
Can I specify an absolute path which is relative to the root folder (if that makes sense)? In other words, I want all references to the style sheet to be href="root/css/style.css", so that all files point to the same place regardless of their location in the file structure.

If you added a slash href="/something/css/cssfile.css" it would be the equivalent of http://www.domain/something/css/cssfile.css. Is that what you mean?
 

conor

New Member
You could do this:
Code:
set_include_path($_SERVER['DOCUMENT_ROOT']);
Then every time you include the document root will be automatically appended. So you could just write this:

Code:
include '/includes/head.php';
include '/includes/body.php';
 
Top