Jonotron Posted September 1, 2009 Share Posted September 1, 2009 Hi, I have a fairly strange folder structure but I'd like to keep it this way. I have an error in one file saying "no such file/directory blah blah..." but it should work. The php file is at /root/admin/ and is asking to access a file at /root/include/ In dreamweaver it can open the other file using the quick link thing but on the page it doesn't work. I'm thinking it has to do with a open_basedir or set_include_path or just something to do with relative paths. I've been googling for hours and I can't seem to find the answer! simple require function: require_once '../include/database.php'; Any help is appreciated Link to comment https://forums.phpfreaks.com/topic/172634-solved-require_once-path-help-should-be-easy/ Share on other sites More sharing options...
MadTechie Posted September 1, 2009 Share Posted September 1, 2009 try this require_once dirname(__FILE__).'/../include/database.php'; Link to comment https://forums.phpfreaks.com/topic/172634-solved-require_once-path-help-should-be-easy/#findComment-909977 Share on other sites More sharing options...
Jonotron Posted September 1, 2009 Author Share Posted September 1, 2009 Thanks a lot! Worked perfectly Can you please explain what that does exactly? Link to comment https://forums.phpfreaks.com/topic/172634-solved-require_once-path-help-should-be-easy/#findComment-909980 Share on other sites More sharing options...
MadTechie Posted September 1, 2009 Share Posted September 1, 2009 Sure, __FILE__ = the full path and name of the current file dirname() function extracts the path from the given parameter result is the path of the current file your in. EDIT: just remember the resulting path doesn't have the leading slash so you need to add it ie __FILE__ // return /root/testing/myfile.php dirname("/root/testing/myfile.php"); // returns /root/testing so dirname(__FILE__); // returns /root/testing so add the / at the end Link to comment https://forums.phpfreaks.com/topic/172634-solved-require_once-path-help-should-be-easy/#findComment-909983 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.