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? Quote Link to comment 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 Quote Link to comment 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"); ?> Quote Link to comment 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? Quote Link to comment 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.