By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
431,943 Members | 1,875 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 431,943 IT Pros & Developers. It's quick & easy.

open_basedir

P: n/a
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.readfile]: 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.txt) [function.readfile]: 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

Jun 24 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
sr*****@wp.pl wrote:
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 ?


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(dirname($_SERVER['PHP_SELF']) .'/test.txt');
HTH;
JW
Jun 25 '06 #2

P: n/a
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.
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 ?
To dynamically determine the absolute path, you could do something like:
readfile(dirname($_SERVER['PHP_SELF']) .'/test.txt');

Thank you, I will use it :)

--
Marcin Kula

Jun 26 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.