Include problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Kupo

    Include problem

    Hi, I'm currently writing website using php. My problem is, when I do:

    include("../../library/file.php"); // this is from e.g
    /level1/level2/something.php

    it works. However, when I use:

    include("../../../library/file.php"); // and this one from
    /level1/level2/level3/something.php

    it doesn't work. So, does the include statement in php only cover 2
    upwards directories? Is there anyway around this?
    Thanks.


    Nic
  • Pedro Graca

    #2
    Re: Include problem

    Kupo wrote:[color=blue]
    > My problem is, when I do:
    >
    > include("../../library/file.php");
    > // this is from e.g /level1/level2/something.php
    >
    > it works. However, when I use:
    >
    > include("../../../library/file.php");
    > // and this one from /level1/level2/level3/something.php
    >
    > it doesn't work.[/color]

    /How/ does it not work?

    it includes a different file? :)
    it gives a error message? ==> try error_reporting (E_ALL);
    what is the error message?
    it just ignores the include()?
    [color=blue]
    > So, does the include statement in php only cover 2
    > upwards directories?[/color]

    No.
    [color=blue]
    > Is there anyway around this?[/color]

    Maybe if you specify the path from the root

    include '/library/file.php';

    no matter how deep you are in the directory structure.
    [color=blue]
    > Thanks.[/color]

    It works for me:

    $ cat /home/pedro/src/php/test.php
    #!/usr/bin/php
    <?php
    error_reporting (E_ALL);
    include 'inc.php';
    include '../php/inc.php';
    include '../../src/php/inc.php';
    include '../../../pedro/src/php/inc.php';
    include '../../../../home/pedro/src/php/inc.php';
    include '../../../../../../../../../home/pedro/src/php/inc.php';
    echo "Done!\n";
    ?>

    $ cat /home/pedro/src/php/inc.php
    <?php
    echo "inside included file\n";
    ?>

    $ cd /home/pedro/src/php
    $ ./test.php
    inside included file
    inside included file
    inside included file
    inside included file
    inside included file
    inside included file
    Done!

    --
    USENET would be a better place if everybody read: : mail address :
    http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
    http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
    http://www.expita.com/nomime.html : to 10K bytes :

    Comment

    • Garp

      #3
      Re: Include problem


      <Kupo> wrote in message news:qt1970hgm5 cfd2aktajgvht8v p8ndidct0@4ax.c om...[color=blue]
      > Hi, I'm currently writing website using php. My problem is, when I do:
      >
      > include("../../library/file.php"); // this is from e.g
      > /level1/level2/something.php
      >
      > it works. However, when I use:
      >
      > include("../../../library/file.php"); // and this one from
      > /level1/level2/level3/something.php
      >
      > it doesn't work. So, does the include statement in php only cover 2
      > upwards directories? Is there anyway around this?
      > Thanks.[/color]

      Have a play with getcwd() to find out where you are, and work it from there.
      Then you have to worry about permissions, chroot jails, etc.

      Garp


      Comment

      Working...