eco Posted June 17, 2009 Share Posted June 17, 2009 Hi guys, I'm back with another question... I hope I can give back to the forum once I get the hang of PHP I am getting the following warning when I execute my PHP script from any other place than the Class folder Warning: require(../config.php): failed to open stream: No such file or directory in /root/API/Class/API.php on line 30 Fatal error: require(): Failed opening required '../config.php' (include_path='.:/usr/share/php5:/usr/share/php') in /root/API/Class/API.php on line 30 The following is the Class API <?php Class API { public function GetUser($name) { require '../config.php'; [...] } public function ListUsers() { require '../config.php'; [...] } The file is indeed where it's meant to be ie '../config.php' but I admit having trouble figuring out require/require_once, etc. Any help or pointers to documentation are welcome -eco Link to comment https://forums.phpfreaks.com/topic/162648-require-problems-failed-to-open-stream/ Share on other sites More sharing options...
ldougherty Posted June 17, 2009 Share Posted June 17, 2009 Instead of using ../ try using the full path to the file. If that still doesn't work then add the path in your include_dir setting in the php.ini Link to comment https://forums.phpfreaks.com/topic/162648-require-problems-failed-to-open-stream/#findComment-858399 Share on other sites More sharing options...
eco Posted June 17, 2009 Author Share Posted June 17, 2009 OK, will do. I just wanted to avoid using a full path so that I could move my code without having to change all the paths but hey, if that will work, it's worth the extra 5 mins work I'll have a look at the include_dir though! Thanks! Link to comment https://forums.phpfreaks.com/topic/162648-require-problems-failed-to-open-stream/#findComment-858404 Share on other sites More sharing options...
gijew Posted June 17, 2009 Share Posted June 17, 2009 If you have a configuration file that loads with each page just create a variable containing the full path so if you ever need to change it you can do so in one place. Link to comment https://forums.phpfreaks.com/topic/162648-require-problems-failed-to-open-stream/#findComment-858412 Share on other sites More sharing options...
ldougherty Posted June 17, 2009 Share Posted June 17, 2009 sorry, i meant to say include_path, not include_dir Link to comment https://forums.phpfreaks.com/topic/162648-require-problems-failed-to-open-stream/#findComment-858413 Share on other sites More sharing options...
eco Posted June 17, 2009 Author Share Posted June 17, 2009 If you have a configuration file that loads with each page just create a variable containing the full path so if you ever need to change it you can do so in one place. Could you give me a quick example? I don't get what you mean. The file is a restricted file that holds the user and password. This is only accessed by a couple of classes. Link to comment https://forums.phpfreaks.com/topic/162648-require-problems-failed-to-open-stream/#findComment-858427 Share on other sites More sharing options...
eco Posted June 17, 2009 Author Share Posted June 17, 2009 sorry, i meant to say include_path, not include_dir Thanks for the clarification... reading about it now Link to comment https://forums.phpfreaks.com/topic/162648-require-problems-failed-to-open-stream/#findComment-858428 Share on other sites More sharing options...
pkedpker Posted June 17, 2009 Share Posted June 17, 2009 /root/API/Class/API.php thats 3 folders.. ../../../config.php so yah Link to comment https://forums.phpfreaks.com/topic/162648-require-problems-failed-to-open-stream/#findComment-858432 Share on other sites More sharing options...
eco Posted June 17, 2009 Author Share Posted June 17, 2009 /root/API/Class/API.php thats 3 folders.. ../../../config.php so yah ... I did say ../config.php was correct as in... it's in /root/API so ../config.php Link to comment https://forums.phpfreaks.com/topic/162648-require-problems-failed-to-open-stream/#findComment-858434 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.