gevans Posted November 17, 2009 Share Posted November 17, 2009 Hey guys, I have an include as follows; include_once(__FILE__."/../Page.inc.php"); which has been working fine. Now in PHP 5.3.x I get a warning; Warning: include_once(C:\xampp\htdocs\example.com\site\pageTemplates\classes\PublicPage.inc.php/../Page.inc.php) [function.include-once]: failed to open stream: No such file or directory in C:\xampp\htdocs\example.com\site\pageTemplates\classes\PublicPage.inc.php on line 7 Changing the code to; include_once(dirname(__FILE__)."/Page.inc.php"); Can anyone explain why this is happening? Quote Link to comment https://forums.phpfreaks.com/topic/181879-upward-linking-in-include_once/ Share on other sites More sharing options...
premiso Posted November 17, 2009 Share Posted November 17, 2009 My bet is the configuration settings in php 5. The old version of PHP could have had a different include path that the new one does not have, either it was defaulted in the older version of PHP or was added manually. Alternatively, I could be completely wrong and they just changed how __FILE__ worked and it now works so that it actually includes the file instead of the directory as it previously did? The only way to get to the bottom is go look at release notes on php.net Quote Link to comment https://forums.phpfreaks.com/topic/181879-upward-linking-in-include_once/#findComment-959252 Share on other sites More sharing options...
JustLikeIcarus Posted November 17, 2009 Share Posted November 17, 2009 Try this include_once(__DIR__ . DIRECTORY_SEPERATOR . 'Page.inc.php'); Quote Link to comment https://forums.phpfreaks.com/topic/181879-upward-linking-in-include_once/#findComment-959255 Share on other sites More sharing options...
gevans Posted November 17, 2009 Author Share Posted November 17, 2009 Try this include_once(__DIR__ . DIRECTORY_SEPERATOR . 'Page.inc.php'); __DIR__ is only available in PHP 5.3.x, and though that's what I'm using locally, it's not available on the production server. My bet is the configuration settings in php 5. The old version of PHP could have had a different include path that the new one does not have, either it was defaulted in the older version of PHP or was added manually. I can't see anything wrong in the settings, and it should skip over the include paths (as the fiels aren't there) and attempt to resolve the absolute path. Alternatively, I could be completely wrong and they just changed how __FILE__ worked and it now works so that it actually includes the file instead of the directory as it previously did? The only way to get to the bottom is go look at release notes on php.net I've had a quick look through the release notes, will have to look a little harder as this is causing hassles all across the system! Cheers guys, gevans Quote Link to comment https://forums.phpfreaks.com/topic/181879-upward-linking-in-include_once/#findComment-959272 Share on other sites More sharing options...
JustLikeIcarus Posted November 17, 2009 Share Posted November 17, 2009 Per the php manual the __FILE__ magic constant returns the path and the file name. Its strange that the way you have been doing it was working correctly since it was going <file>/../ which isnt a valid path. so your better changing it now to save any future headaches. Maybe this way? include_once(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'Page.inc.php'); Quote Link to comment https://forums.phpfreaks.com/topic/181879-upward-linking-in-include_once/#findComment-959286 Share on other sites More sharing options...
gevans Posted November 17, 2009 Author Share Posted November 17, 2009 As mentioned in my first post it was fixed with a 'similar' solution (not using DIRECTORY_SEPERATOR). I'm doing this for another company so am not gonna fix there code unless I'm getting paid for it. Just wanted to make sure it wasn't something caused by my setup! Thanks again, gevans Quote Link to comment https://forums.phpfreaks.com/topic/181879-upward-linking-in-include_once/#findComment-959379 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.