Using include - help

Discussion in 'PHP' started by junkmailbox53, Aug 31, 2008.

  1. #1
    How do I write an include to another file in another folder or point to another folder and files outside the directory ...

    FILE2.PHP

    <?php include("/foldername2/fileB.inc"); ?>


    folder and files within ... One file I want to use an include


    /foldername1/
    FILE1.inc
    FILE2.inc
    FILE3.inc


    /foldername2/

    fileA
    fileB
    fileC
     
    junkmailbox53, Aug 31, 2008 IP
  2. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #2
    you can use ../ to go up a directory
    say for example, you have

    /root/folder1/script1.php
    and
    /root/folder2/script2.php

    you can call script2 from script1 using

    include('../folder2/script2');
    PHP:
     
    JAY6390, Aug 31, 2008 IP
  3. junkmailbox53

    junkmailbox53 Peon

    Messages:
    69
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    wow...this was great.... I'm going to try...

    HVE a coffee on me.
     
    junkmailbox53, Aug 31, 2008 IP
  4. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #4
    well, i can't stand coffee, but thanks lol
     
    JAY6390, Aug 31, 2008 IP
  5. ForumJoiner

    ForumJoiner Active Member

    Messages:
    762
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    83
    #5
    Some programs use the "absolute path" approach. For instance, here's an excerpt from the file wp-config.php, from WordPress 2.6.1:
    
    <?php
    	define('ABSPATH', dirname(__FILE__) .'/');
    	require_once(ABSPATH . 'wp-settings.php');
    ?>
    PHP:
    The advantage of this method is that you don't have to know how many folders to go up, but what's the absolute path to your file. It's way much easier.
     
    ForumJoiner, Aug 31, 2008 IP
  6. Ilyes

    Ilyes Banned

    Messages:
    129
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Right JAY6390
    include('../folder2/script2');
    PHP:
    It's like in html when you link...
     
    Ilyes, Sep 1, 2008 IP