Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2004
    Location
    Germany
    Posts
    536

    php include file in web root directory?

    How do I include a php file that I have in the web root directory while I am am running a php file in another directory?

    for example.

    in my home directory I have a navbar.php file and my main.css

    I am running a file in /output call team.php

    How do I get the output/team.php to include the files in my root directory (navbar and main.css)?

    /
    main.css
    navbar.php
    /output/team.php
    Last edited by jwr; 12-17-2010 at 09:02 AM.
    KiwiJay

    The Kiwi in Germany
    “veni, vidi, vici Maya.”

  2. #2
    Join Date
    Dec 2009
    Location
    United Kingdom
    Posts
    60
    this ../ allows you to go back a directory

    include("../main.css");
    include("../navbar.php");

  3. #3
    Join Date
    Oct 2004
    Location
    Germany
    Posts
    536
    I tried that but I run into the problem that I have links in the navbar folder that now don't match up. It keeps adding the output folder name in all it's links.

    I.e
    /
    /images
    /output

    link going to images folder so it does images/output where I want it just to look in images
    KiwiJay

    The Kiwi in Germany
    “veni, vidi, vici Maya.”

  4. #4
    Join Date
    Dec 2009
    Location
    United Kingdom
    Posts
    60
    in the navbar.php file

    place a / before your links like so

    <a href='/news.php'>news</a>
    <img src='/images/banner.jpg' width='100'' height='100' alt=''' />

    the / should make the link refer to the root directory.
    Last edited by zOrigin; 12-17-2010 at 10:45 AM. Reason: typo

  5. #5
    Join Date
    Apr 2004
    Location
    Nr London, UK
    Posts
    831
    include($_SERVER['DOCUMENT_ROOT']./rootfile.php');

    define some global vars that do that say

    define(WEB_ROOT, $_SERVER['DOCUMENT_ROOT']);
    define(PHP_DIR, WEB_ROOT.'/php');

    include(WEB_ROOT.'/rootfile.php');
    include(PHP_DIR.'/file.php');

Posting Permissions

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