Forum Moderators: coopster

Message Too Old, No Replies

require once relative path issues php5

         

planedriver

10:12 pm on Mar 26, 2009 (gmt 0)

10+ Year Member



In php4 this worked:

require_once ('../../../path/to/include/file.php'); if the file to be included was outside the document root directory.

but I recently was forced to upgrade to php5 and apparently there is a bug in the require/include statements.

I was told by someone on Experts Exchange to use the following syntax:

require_once (dirname(dirname(dirname(__FILE__))) . 'path/to/include/file.php');

I can do require/include as long as the file to be included is inside the document root (even multiple directories deep) but anything outside is not found.

Any thoughts?

eeek

10:20 pm on Mar 26, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



As a test do:

echo dirname(dirname(dirname(__FILE__))) . 'path/to/include/file.php';

If the output looks like what you want, try plugging it into require.

planedriver

11:15 pm on Mar 26, 2009 (gmt 0)

10+ Year Member



i tried that and it output the path correctly... (actually i used the 'print' statement) still didn't work when i put it in the require statement.

eeek

12:17 am on Mar 27, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



You aren't in safe mode are you?

planedriver

1:15 am on Mar 27, 2009 (gmt 0)

10+ Year Member



nope.

eeek

11:35 pm on Mar 27, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What does phpinfo() say?