Results 1 to 2 of 2

Thread: PHP include - root relative path?

  1. #1
    Join Date
    Aug 2004
    Posts
    34

    PHP include - root relative path?

    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

    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.

  2. #2
    Join Date
    Apr 2006
    Posts
    404
    "../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.

Similar Threads

  1. logo image not shown: PHP include relative root path?
    By web88js in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 0
    Last Post: 04 Oct 2007, 06:36 PM
  2. Something like a php include
    By pilotdesigns in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 0
    Last Post: 07 Sep 2006, 02:28 PM
  3. PHP Include: If file not found, can i direct to a default file?
    By ukcoolat in forum Client & Server Side Scripting (PHP, ASP, JavaScript)
    Replies: 1
    Last Post: 04 Nov 2005, 10:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •