remenissions Posted October 23, 2011 Share Posted October 23, 2011 Hey all, I've been having an issue with require_once from another sub-directory. Origionally I had all my php files in the same spot but I wanted to make a library to clean things up a bit. Atm I am trying to access my /subFolder/frame_work/sql/dbconnect.rem.php with require once from /subFolder/frame_work/account_data/accountHandler.rem.php. I have looked around a little bit and i know requires\includes looks in relative directorys. So one obvious solution would be to include the entire path name. "var/www/subFolder/frame_work/sql/dbconnect.rem.php". My problem is I will be accessing this from multiple directories and on localhost the root directory is var opposed to my server which is public_html. I like to edit my stuff in localhost before going public with it and it is going to be a real pain if I have to keep switching var to public_html in every file before I upload. Is there any other solutions I could approach? Any responses would be much appreciated. Thank you for your time. Quote Link to comment https://forums.phpfreaks.com/topic/249646-require-from-another-sub-directory/ Share on other sites More sharing options...
remenissions Posted October 23, 2011 Author Share Posted October 23, 2011 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/249646-require-from-another-sub-directory/#findComment-1281625 Share on other sites More sharing options...
xyph Posted October 23, 2011 Share Posted October 23, 2011 Give me a good reason that you can't use absolute paths Leave relative paths for basic relationships... ../../../ gets ugly $_SERVER['DOCUMENT_ROOT'] and $_SERVER['SCRIPT_FILENAME'] will help with this Quote Link to comment https://forums.phpfreaks.com/topic/249646-require-from-another-sub-directory/#findComment-1281640 Share on other sites More sharing options...
remenissions Posted October 24, 2011 Author Share Posted October 24, 2011 Thank you for your reply, I had never looked into this really. I saw a couple posts about it but didn't quite understand it at first glance. Just tested it with a simple <?php echo $_SERVER["DOCUMENT_ROOT"]."<br>".$_SERVER['SCRIPT_FILENAME']; ?> Its just what I needed :], thank you. Quote Link to comment https://forums.phpfreaks.com/topic/249646-require-from-another-sub-directory/#findComment-1281666 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.