Jump to content

[SOLVED] Directory path references #1


jeffrydell

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/64485-solved-directory-path-references-1/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.