open_basedir

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sreniaw@wp.pl

    #1

    open_basedir

    Hello,
    I use php 5.1.4 with apache 2.2.2 on Solaris 10.
    The problem is that I can't configure open_basedir
    because I always get warming message:

    Warning: readfile() [function.readfi le]: open_basedir restriction in
    effect. File(test.txt) is not within the allowed path(s):
    (/wwwroot/default) in /wwwroot/default/mk.php on line 3
    Warning: readfile(test.t xt) [function.readfi le]: failed to open stream:
    Not owner in /wwwroot/default/mk.php on line 3

    open_basedir = /wwwroot/default
    /wwwroot/default
    - test.txt <- my txt file
    - mk.php <- my script that read test.txt
    <?
    readfile("test. txt");
    ?>

    My read file - test.txt is in open_basedir path.
    When I use full path to the file everything is ok.

    Do you have any clue ?

    --
    Marcin

  • Janwillem Borleffs

    #2
    Re: open_basedir

    sreniaw@wp.pl wrote:[color=blue]
    > My read file - test.txt is in open_basedir path.
    > When I use full path to the file everything is ok.
    >
    > Do you have any clue ?
    >[/color]

    Image the following situation:

    The text and script files are in the following dir:

    /somedir/subdir

    The script file includes the text file relatively to the current working
    dir, as in:

    readfile('test. txt');

    The open_basedir directive is set as follows:

    open_basedir = /somedir/subdir

    Now, you cd to /somedir/subdir and execute the script: all is fine.

    Next, you cd to /somedir and execute the script: it fails. Why?

    Because you include the text file relatively to the current working dir
    (cwd), PHP expects the text file to be in /somedir, simular to:

    readfile('/somedir/test.txt');

    And this is restricted, hence the error message. For this reason, using an
    absolute path works, because this doesn't take the cwd into account.

    The same applies to the safe_mode settings, which you also seem to use
    according to the "Not owner" error.

    To dynamically determine the absolute path, you could do something like:

    readfile(dirnam e($_SERVER['PHP_SELF']) .'/test.txt');


    HTH;
    JW


    Comment

    • Marcin

      #3
      Re: open_basedir

      [color=blue]
      > Now, you cd to /somedir/subdir and execute the script: all is fine.
      > Next, you cd to /somedir and execute the script: it fails. Why?
      >
      > Because you include the text file relatively to the current working dir
      > (cwd), PHP expects the text file to be in /somedir, simular to:
      >
      > readfile('/somedir/test.txt');
      >
      > And this is restricted, hence the error message. For this reason, using an
      > absolute path works, because this doesn't take the cwd into account.[/color]

      You are right, but problem isn't in it.
      On my home's FreeBSD box evrything works ok, but
      on Solaris 10 I have to use absolute path's.
      Why do I have to do it ?
      [color=blue]
      > To dynamically determine the absolute path, you could do something like:
      > readfile(dirnam e($_SERVER['PHP_SELF']) .'/test.txt');[/color]
      Thank you, I will use it :)

      --
      Marcin Kula

      Comment

      Working...