Results 1 to 3 of 3

Thread: About paths when including files

  1. #1
    Join Date
    Oct 2008
    Posts
    42
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default About paths when including files

    Hi friends,

    I don't know how to explain this.

    I am confusing when regarding including files.

    suppose I have these stuff in my script:

    folder1/test1.php

    folder2/test2.php

    index.php

    if I need to include test1.php file to be inside test2.php file, I use this function
    PHP Code:
    require"../folder1/test1.php"// (correct right???). 
    if I need to call test2.php to be available in index.php, I use this

    PHP Code:
    require("folder2/test2.php"); // (correct right???). 
    but the problem it will refuse the first path which we include first.
    PHP Code:
    require"../folder1/test1.php"
    bcs "../" means from folder to folder

    how can I make all paths readable???

  2. #2
    Join Date
    Feb 2009
    Posts
    303
    Thanks
    18
    Thanked 36 Times in 36 Posts

    Default

    I'm not really getting what you're driving at...

    To include a file, you use the include() function, not require...

    So I think what you need to do is use:
    test2.php
    Code:
    <?php include('../folder1/test1.php'); ?>
    index.php
    Code:
    <?php include('folder2/test2.php'); ?>
    Like that...

    Is that what you're trying to do? Make test1.php show up in test2.php, and test2.php show up in index.php?

    Hope that helps...

    // X96 \\
    Alex Blackie, X96 Design
    My Website
    I specialize in: HTML5, CSS3, PHP, Ruby on Rails, MySQL, MongoDB, Linux Server Administration

  3. #3
    Join Date
    Mar 2009
    Location
    Chennai, India
    Posts
    77
    Thanks
    16
    Thanked 7 Times in 6 Posts

    Default

    When you include test2.php, test2.php becomes a part of index.php... So, it executes all the lines as if it were a part of index.php...


    So, code in test2.php should be
    Code:
    require("folder1/test1.php");
    or
    Code:
    include("folder1/test1.php");


    Require() does everything that include() does, but the only difference is, it will not execute the rest of the code if it is unable to include the file...

    But this will not work if you include test2.php in another php file which is also in folder2....

Bookmarks

Posting Permissions

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