SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question problem of require_once() with relative path.. is it a bug or normal behaviour

    say if i do an include within an include an if i use relative paths it does not work.

    HTML Code:
    i have directory structure as follows:
    <pre>
    c:\web -- index.php
    c:\web\framework --- errorhandler(folde),debugger (folder), index.php
    
    c:\web\framework\errorhandler -- class.error.php
    </pre>
    1) c:\web\index.php -- include("framework/include.php") //correct

    2) c:\web\include.php -- include("errorhandler/class.error.php //correct

    3) c:\web\framework\errorhandler\class.error.php -- a) include("../include.php")//wrong error saying cannot open dtream
    b) include("include.php")/right

    3(b)should be wrong but in actual its viceversa.
    3(a)is wrong and 3(b) is right


    is it a bug or is it supposed to be like this.

  2. #2
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Its kind of hard to explain this.....

    -->blocks
    ------>headblock.php
    -->templates
    ------>header.php
    index.php

    Say, if you have index.php

    PHP Code:
    <?php
    include('templates/header.php');
    ?>
    And you have header.php

    PHP Code:
    <?php
    include('../blocks/head.php'); //This wont work
    include('blocks/head.php'); // This will work
    ?>
    Becuase you inlcude the header.php in the index.php file then all the include in the header.php file need to be in relation to where files are stored in comparison to the index.php

    I hope this makes sense.

    Mark

  3. #3
    Umm. PHP Guru....Naaaah jaswinder_rana's Avatar
    Join Date
    Jul 2004
    Location
    canada
    Posts
    3,193
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    so what i understood is position in require or anything is relative to where we are including the file not the actual position. RIGHT??

    so, does it mean we should use absolute path because say we are including one file blocks/head.php which is relative to it. but it might not work if its not relative to index.php at the same path. RIGHT???

    or should i use ini_set to reflect the different locations
    or any other solution to work over this
    thanks for the answer Mark.

  4. #4
    SitePoint Wizard mark_W's Avatar
    Join Date
    Mar 2004
    Location
    West Midlands, United Kingdom
    Posts
    2,631
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    If you use absolute paths then try and use something like $_SERVER['DOCUMENT_ROOT'] and the include in relation to that. That might help you.

    Mark


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
  •