jeffrydell Posted August 12, 2007 Share Posted August 12, 2007 First - this applies to a Windows server ... I know, I know - I don't need the lecture ... it's the last site I'm maintaining on Windows and I just haven't had time to migrate it. Let's say I have a little script which is used to open the MySQL db on my site (which I do) and it 'lives' in the folder called admin under the document root (which it does) and it's called mike.php (which it isn't - so don't go looking for it. I understand how to access 'Mike' from a script in the document root: require_once('admin/mike.php'); ... and I understand how to reference 'Mike' from a script that may be down a directory from the document root: require_once('../admin/mike.php'); BUT what about when I want to reference from a script that is 'included' from another script in a different directory ... and that script could either be 'included' ... or might just be running on its own? I'm running in to a problem with not being able to write that reference to /admin/mike.php correctly because sometimes I'm referring to it from the 'wrong' level. Example (where ScriptB.php calls for mike.php): ScriptA is in the document root and has a line that reads: include('/subscripts/ScriptB.php'); ... because it was 'included' from the document root, the reference to open the db should be: require_once('admin/mike.php'); BUT that won't work if ScriptB.php is called from itself, or from another script in the /subscripts/ folder... now it must use: require_once('../admin/mike.php'); So here's the question ... how can I write the reference to mike.php in such a way that it will work no matter how the script is initiated? Is there a universal way of saying 'look for this file in the the admin folder under the document root'? Thanks in advance for your patience and help! Quote Link to comment https://forums.phpfreaks.com/topic/64485-solved-directory-path-references-1/ Share on other sites More sharing options...
sasa Posted August 12, 2007 Share Posted August 12, 2007 include($_SERVER['DOCUMENT_ROOT'].'/admin/mike.php'); Quote Link to comment https://forums.phpfreaks.com/topic/64485-solved-directory-path-references-1/#findComment-321469 Share on other sites More sharing options...
jeffrydell Posted August 12, 2007 Author Share Posted August 12, 2007 Never knew that existed. Thanks - solves a lot of issues for this project! Quote Link to comment https://forums.phpfreaks.com/topic/64485-solved-directory-path-references-1/#findComment-321567 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.