steelmanronald06 Posted December 3, 2006 Share Posted December 3, 2006 I can't believe that this has happened to me. I should be good enough now that this shouldn't be a problem, but of course I am just not seeing the problem.[b]Error[/b][quote]Warning: require_once(includes/tmp/top_layout.php) [function.require-once]: failed to open stream. No such file or directory in C:\wamp\www\blakes\includes\config.php on line 43Fatal error: require_once() [function.require]: Failed opening required 'includes/tmp/top_layout.php' (include_path='.;C:\php5\pear') in C:\wamp\www\blakes\includes\config.php on line 43[/quote][b]config.php line 43[/b][code]function topLayout() {require_once($path . 'includes/tmp/top_layout.php);}[/code]Now if I do this from C:\wamp\www\blakes\index.php it works. But if I try from C:\wamp\www\blakes\admin\login.php I get the error. Here is what the login.php does:[code]$path = "../";require_once($path . 'includes/config.php');topLayout();[/code]So does anyone else see what I'm not seeing? Quote Link to comment https://forums.phpfreaks.com/topic/29281-solved-require-problem/ Share on other sites More sharing options...
kenrbnsn Posted December 3, 2006 Share Posted December 3, 2006 Where is $path defined in this function?[code]<?phpfunction topLayout() {require_once($path . 'includes/tmp/top_layout.php);}?>[/code]Either pass as a parameter or use the global statement.Ken Quote Link to comment https://forums.phpfreaks.com/topic/29281-solved-require-problem/#findComment-134216 Share on other sites More sharing options...
Zane Posted December 3, 2006 Share Posted December 3, 2006 maybe make $paththis$path = "../../";insteadperhaps Quote Link to comment https://forums.phpfreaks.com/topic/29281-solved-require-problem/#findComment-134217 Share on other sites More sharing options...
genericnumber1 Posted December 3, 2006 Share Posted December 3, 2006 is the file you're trying to include C:\wamp\www\includes\tmp\top_layout.phporC:\wamp\www\blakes\includes\tmp\top_layout.php?if it's the first one it would work to set the $path in login.php to "../../" Quote Link to comment https://forums.phpfreaks.com/topic/29281-solved-require-problem/#findComment-134218 Share on other sites More sharing options...
steelmanronald06 Posted December 3, 2006 Author Share Posted December 3, 2006 It is in the second one you listed...and the ../../ didn't work.ken, the $path is defined in the file that config.php is included in...defined BEFORE the file is included. Quote Link to comment https://forums.phpfreaks.com/topic/29281-solved-require-problem/#findComment-134220 Share on other sites More sharing options...
kenrbnsn Posted December 3, 2006 Share Posted December 3, 2006 But, you're within a function, variables defined outside the function are not available to the function unless they are declared global inside the function or passed in via an argument.[code]<?phpfunction topLayout() { global $path; // add this statement require_once($path . 'includes/tmp/top_layout.php);}?>[/code]Ken Quote Link to comment https://forums.phpfreaks.com/topic/29281-solved-require-problem/#findComment-134222 Share on other sites More sharing options...
steelmanronald06 Posted December 3, 2006 Author Share Posted December 3, 2006 that worked. thanks:) Quote Link to comment https://forums.phpfreaks.com/topic/29281-solved-require-problem/#findComment-134224 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.