Jump to content

Organizing PHP scripts in folders


Shadowing

Recommended Posts

so is it impossible if I have a users folder and a messaging folder located in the same folder.

 

To have a script in the users folder reading from the messaging folder

 

from a script in the messaging folder i thought i could just do this to read the users folder but apparently not

 

<? require("users/menu.php"); ?>

Link to comment
https://forums.phpfreaks.com/topic/253026-organizing-php-scripts-in-folders/
Share on other sites

For absolute paths you can use a couple things to avoid hardcoding the "/root/to/folder" part.

$_SERVER["DOCUMENT_ROOT"] . "/users/menu.php"

dirname(__FILE__) . "/../users/menu.php" // looks relative but is actually absolute
__DIR__ . "/../users/menu.php" // same for PHP 5.3+

There's a third and maybe fourth I'm forgetting.

 

I tend to avoid strictly relative paths because they're relative to the current working directory, and that's not always the same directory as the executing script. If you aren't aware of when it does(n't) change then the File Not Found errors can drive you crazy.

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.