Topic: require_once() and relative paths...

anyone know how I can get a relative path to work with the include_once function?

Daniel Marino | www.iamdanielmarino.com

Re: require_once() and relative paths...

require_once(__DIR__ . "/relative/path/to/file");

Re: require_once() and relative paths...

This doesn't seem to work - I've tried both these:

require_once(__DIR__ . "/php/simplepie.inc");

require_once __DIR__ . "/php/simplepie.inc";

I get this error either way:

Warning: require_once(__DIR__/php/simplepie.inc) [function.require-once]: failed to open stream: No such file or directory in /blah/blah/blah/blah/news/index.php on line 4

Fatal error: require_once() [function.require]: Failed opening required '__DIR__/php/simplepie.inc' (include_path='.:/some/really/really/really/long/url/lib/php') in /blah/blah/blah/blah/news/index.php on line 4

Daniel Marino | www.iamdanielmarino.com

Re: require_once() and relative paths...

I thought __DIR__ was just and example he was using until I googled it!  Looks like that's a reserved variable for PHP 5.3, so you may be using an older version of PHP.

Check this page out: http://usrportage.de/archives/878-New-m … P-5.3.html

Re: require_once() and relative paths...

If you are on php 4 you would use dirname(__FILE__) in place of __DIR__ also it's still a relative path so, if you are in the file /foo/bar/baz.php and you want to access /biz/bang/boo.php you would use require_once(__DIR__ . "/../../biz/bang/boo.php)

Re: require_once() and relative paths...

try this: require_once($_SERVER['DOCUMENT_ROOT']. "/php/simplepie.inc");

Re: require_once() and relative paths...

used aim's method - worked like a charm. Thanks

Daniel Marino | www.iamdanielmarino.com