A Small Help Neded - Php Include

Discussion in 'PHP' started by koolasia, Mar 7, 2007.

Thread Status:
Not open for further replies.
  1. #1
    what i need is

    how do i include a file in this situation

    this file is in foldet "test"

    and the file i want to include is in root

    how do i do this
     
    koolasia, Mar 7, 2007 IP
  2. cbn81

    cbn81 Peon

    Messages:
    160
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    0
    #2
    include('..\file.inc'';
     
    cbn81, Mar 7, 2007 IP
  3. designcode

    designcode Well-Known Member

    Messages:
    738
    Likes Received:
    37
    Best Answers:
    0
    Trophy Points:
    118
    #3
    include("../yourfile.php");

    or

    include($_SERVER['DOCUMENT_ROOT'] . "yourfile.php");
     
    designcode, Mar 7, 2007 IP
  4. Lovers_Rock

    Lovers_Rock Active Member

    Messages:
    121
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    58
    #4
    u can use
    <? include "xxx.php"; ?> easyest way :)
    PHP:
     
    Lovers_Rock, Mar 7, 2007 IP
  5. ablaye

    ablaye Well-Known Member

    Messages:
    4,024
    Likes Received:
    97
    Best Answers:
    0
    Trophy Points:
    150
    #5
    Need more help???
     
    ablaye, Mar 7, 2007 IP
  6. Louis11

    Louis11 Active Member

    Messages:
    783
    Likes Received:
    26
    Best Answers:
    0
    Trophy Points:
    70
  7. koolasia

    koolasia Banned

    Messages:
    1,413
    Likes Received:
    59
    Best Answers:
    0
    Trophy Points:
    0
    #7
    thanks guys
     
    koolasia, Mar 7, 2007 IP
  8. php_daemon

    php_daemon Active Member

    Messages:
    34
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    95
    #8
    Personally, I define a constant ROOT in a root.php script file which then is included with include_once() in every file. ROOT stores a relative path to the root, for example '../' for a first level sub directory.

    Then you can always access any point in the hierarchy, for example in a file root/classes/sample_class.php you can include a file root/template/sample_template.php:
    include_once("root.php");
    include(ROOT."templates/sample_template.php");
    
    PHP:
    Hope it makes sense. :)
     
    php_daemon, Mar 8, 2007 IP
Thread Status:
Not open for further replies.