require_once relative path results in fatal error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
LeoT
Forum Newbie
Posts: 3
Joined: Tue Apr 27, 2010 12:18 pm

require_once relative path results in fatal error

Post by LeoT »

The below code result in 2 errors even though i've added the folder location to the included_path directive. the code works fine only if i specify the the absolute path in the require_once function. I can't figure out why. Any help would be very much appreciated
thanks

Code: Select all

 
require_once('magpierss/rss_fetch.inc');

// Compile array of feeds
$feeds = array("http://news.com.com/2547-1_3-0-5.xml");
// Iterate through each feed
foreach ($feeds as $feed) {
// Retrieve the feed
$rss = fetch_rss($feed);
// Format the feed for the browser
$feedTitle = $rss->channel['title'];
echo "<p><strong>$feedTitle</strong><br />";
foreach ($rss->items as $item) {
$link = $item['link'];
$title = $item['title'];
$description = isset($item['description']) ? $item['description'].
"<br />" : "";
echo "<a href=\"$link\">$title</a><br />$description";
}
echo "</p>";
}
[text]Warning: require_once(magpierss/rss_fetch.inc) [function.require-once]: failed to open stream: No such file or directory in /Users/home/Sites/Zend/workspaces/DefaultWorkspace/ExampleProject/testFile.php on line 10
Fatal error: require_once() [function.require]: Failed opening required 'magpierss/rss_fetch.inc' (include_path='.:/usr/local/PEAR:/usr/lib/php/includes/smarty:/usr/lib/php/includes/magpierss') in
/Users/home/Sites/Zend/workspaces/DefaultWorkspace/ExampleProject/testFile.php on line 10[/text]
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: require_once relative path results in fatal error

Post by Benjamin »

What is the full path to rss_fetch.inc?
LeoT
Forum Newbie
Posts: 3
Joined: Tue Apr 27, 2010 12:18 pm

Re: require_once relative path results in fatal error

Post by LeoT »

the full path is [text]HD/usr/lib/php/includes/magpierss/rss_fetch.inc[/text]
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: require_once relative path results in fatal error

Post by Benjamin »

Change it to:

Code: Select all

require_once('rss_fetch.inc');
But note that "HD/usr/lib/php/includes/magpierss/" is not equal to "/usr/lib/php/includes/magpierss".
LeoT
Forum Newbie
Posts: 3
Joined: Tue Apr 27, 2010 12:18 pm

Re: require_once relative path results in fatal error

Post by LeoT »

Thanks Ben. HD is my hard drive. should it have been included in the path?
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: require_once relative path results in fatal error

Post by Benjamin »

LeoT wrote: should it have been included in the path?
If that's the actual path, yes.
Post Reply