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 Quote Link to comment 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 Quote Link to comment 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! Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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.