Shadowing Posted December 12, 2011 Share Posted December 12, 2011 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"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/253026-organizing-php-scripts-in-folders/ Share on other sites More sharing options...
xyph Posted December 12, 2011 Share Posted December 12, 2011 Use either absolute paths /root/to/folder/users/menu.php Or relative ../users/menu.php Quote Link to comment https://forums.phpfreaks.com/topic/253026-organizing-php-scripts-in-folders/#findComment-1297235 Share on other sites More sharing options...
requinix Posted December 12, 2011 Share Posted December 12, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/253026-organizing-php-scripts-in-folders/#findComment-1297238 Share on other sites More sharing options...
Shadowing Posted December 12, 2011 Author Share Posted December 12, 2011 thanks guys, been wondering that for ever i like being organized. Quote Link to comment https://forums.phpfreaks.com/topic/253026-organizing-php-scripts-in-folders/#findComment-1297244 Share on other sites More sharing options...
Winstons Posted December 12, 2011 Share Posted December 12, 2011 Last two xyph's examples is priority, because $_SERVER["DOCUMENT_ROOT"] depends from php.ini or httpd.conf settings. Quote Link to comment https://forums.phpfreaks.com/topic/253026-organizing-php-scripts-in-folders/#findComment-1297246 Share on other sites More sharing options...
Shadowing Posted December 12, 2011 Author Share Posted December 12, 2011 i tried the relative way it didnt work how far back on the dir do i have to go require "/users/menu.php"; this is where my folder is located C:\Software\XAMPP\xampp\htdocs\gate\Users Quote Link to comment https://forums.phpfreaks.com/topic/253026-organizing-php-scripts-in-folders/#findComment-1297254 Share on other sites More sharing options...
Winstons Posted December 12, 2011 Share Posted December 12, 2011 If your folder located on higher level you must write require "../users/menu.php"; Or yet higher require "../../users/menu.php"; Quote Link to comment https://forums.phpfreaks.com/topic/253026-organizing-php-scripts-in-folders/#findComment-1297261 Share on other sites More sharing options...
Shadowing Posted December 12, 2011 Author Share Posted December 12, 2011 C:\Software\XAMPP\xampp\htdocs\gate\messages\inbox.php inbox file is trying to read menu.php C:\Software\XAMPP\xampp\htdocs\gate\Users\menu.php Quote Link to comment https://forums.phpfreaks.com/topic/253026-organizing-php-scripts-in-folders/#findComment-1297266 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.