PDA

View Full Version : PHP include - root relative path?



web88js
04 Oct 2007, 06:49 PM
Hello everyone:

I need some help to understand how php file structure works when using 'include' function.

In my case I want to use include function to use the content in header.php and footer.php file.

My file structure is shown below:
file structure image (http://cuj06.com/home_page/homepage-filestructure.gif)

the site directory is called home_page. home_page contains folder: includes, css, images, projects. home_page_layout.php file is on the same level with these folders.

a) in home_page_layout.php file, I used <?php include('includes/header.php'); ?> to access header.php file

b) In header.php file I need to access global.css and navbar.css file in order to get the styles

I think i am confused between root lative path and document relative path

I first used @import url(../css/global.css); in header.php file I didn't get any style on the home page, then, I changed it to @import url(css/global.css); it worked. Home page (home_page_layout.php) have the styles defined in global.css file.

My understanding is that home_page_layout.php is the actual file which needs to access the global.css file. Hence, I need to use document relative path: css/global.css. If I am using ../css/global.css, it means that home page file needs to go up one level to access global.css file (which doesn't match the file structure for the site).

Please help me to understand how this file structure(path) works. If you have good online resource to explain how file path works for PHP file please share with me. Thanks!

URL for the sample site. (http://www.cuj06.com/home_page/home_page_layout.php)

iblastoff
04 Oct 2007, 11:59 PM
"../css/global.css" will try to find your css file in root/css. your css directory is root/home_page/css. so obviously it wouldn't find it.