parka Posted March 18, 2008 Share Posted March 18, 2008 I've a submit.php in the directory /classifieds/submit.php /inc index.php <?php //submit.php require_once('../inc/include_fns.php'); ?> When I switch the path inside require_once() to root relative, it doesn't work. Apparently, it must have jumped even further up the hierarchy. require_once('/inc/include_fns.php'); So I'm guessing the root directory PHP is seeing is not what I think it is. On my computer, the actual file path is /Macintosh HD/Users/MyName/Sites/htdocs/MySite/classifieds/submit.php I need my root directory to be "MySite". But how can I get PHP to realise what root directory I want? Link to comment https://forums.phpfreaks.com/topic/96648-help-needed-on-file-directory-structure/ Share on other sites More sharing options...
Malevolence Posted March 18, 2008 Share Posted March 18, 2008 file.php = a file in the same directory /file.php = a file in the same folder as your homepage (aka, localhost) ./file.php = a file in the same directory ../file.php = a file in 1 directory back ../../file.php = a file in 2 directories back ../../../file.php = a file in 3 directories back etc. Of course, you could use $_SERVER predefined variables - Click Here Link to comment https://forums.phpfreaks.com/topic/96648-help-needed-on-file-directory-structure/#findComment-494593 Share on other sites More sharing options...
keeB Posted March 18, 2008 Share Posted March 18, 2008 <?php require_once(dirname(__FILE__) . "../relative/path/to/where/you/need/to/be.php"); ?> Link to comment https://forums.phpfreaks.com/topic/96648-help-needed-on-file-directory-structure/#findComment-494594 Share on other sites More sharing options...
parka Posted March 18, 2008 Author Share Posted March 18, 2008 Thanks for the replies. I'm thinking of using this code: <?php require_once($_SERVER['DOCUMENT_ROOT'] . '/some/file/path.php'); ?> I guess this can be easily ported over to any server without problems? Link to comment https://forums.phpfreaks.com/topic/96648-help-needed-on-file-directory-structure/#findComment-494657 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.