Scripting from different directories of the same level

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jalbautista
Forum Newbie
Posts: 5
Joined: Mon Jul 20, 2009 10:50 am

Scripting from different directories of the same level

Post by jalbautista »

Hello! How can I access a script from a directory when I currently executing a script from another directory of the same level as the first directory? Example:

I have a script that prints a form containing a drop-down menu. It is located in http://localhost/root/scripts. The options of that menu will come from a script in http://localhost/root/queries.

http://localhost/root/scripts/menu.php:
<form name='input' action='index.php?page=queries/insert_class' method='post' >
<p><label for='addcl_ctitle'>Course Title: </label><select name='coursetitle' id='ctitle_menu'><this is where i put the option-generating script></select></p>
</form>

I'm OC when it comes to files, so I don't want querying scripts(the options are queried? from a database) in the same folder of my form-generating scripts. Is there a way that I can implement this? I'm a beginner in PHP so I don't know if this is possible.

Thanks in advance!
jalbautista
Forum Newbie
Posts: 5
Joined: Mon Jul 20, 2009 10:50 am

Re: Scripting from different directories of the same level

Post by jalbautista »

hahaha don't bother answering... I found it. I can access it using $_SERVER['DOCUMENT_ROOT']. Silly me :oops:
Randwulf
Forum Commoner
Posts: 63
Joined: Wed Jan 07, 2009 7:07 am

Re: Scripting from different directories of the same level

Post by Randwulf »

You could also use '..'

'..' basically means "root directory". It works like this:

A folder called 'data' has two subfolders, 'big' and 'small'. You want to include a script from the 'small' directory in a script in the 'big' directory. You'd write it like this in the script in the 'big' directory:

Code: Select all

 
include "../small/file.php";
That's saying "move back into the root directory (data), and then go to the 'small' folder and then include the file.php file".
jalbautista
Forum Newbie
Posts: 5
Joined: Mon Jul 20, 2009 10:50 am

Re: Scripting from different directories of the same level

Post by jalbautista »

Thank you very much! I'll try that. :D
Post Reply