priyankabhar Posted September 14, 2012 Share Posted September 14, 2012 Hi, I am building a website in my localhost using WAMP. I have few folder down the main project folder. And now, I have to include a file from another folder which is 2 steps higher. I used $_SERVER['DOCUMENT_ROOT'] to get the website root folder. However, I only get C:/wamp/www/. I need to get C:/wamp/www/mywebsitefolder. How do I get this so that I can include a file from the mywebsitefolder folder and from mywebsitefolder/recipes folder. I want to use absolute paths to avoid rewriting every time I change the directory structure. Any suggestions would be appreciated. It seems include does not allow urls to be used and needs file paths. Thanks a lot! Priya Link to comment https://forums.phpfreaks.com/topic/268353-how-to-get-website-root-folder-for-include/ Share on other sites More sharing options...
trq Posted September 14, 2012 Share Posted September 14, 2012 $_SERVER['DOCUMENT_ROOT'] . '/mywebsitefolder' Link to comment https://forums.phpfreaks.com/topic/268353-how-to-get-website-root-folder-for-include/#findComment-1377807 Share on other sites More sharing options...
Christian F. Posted September 15, 2012 Share Posted September 15, 2012 I think that you might want to use $_SERVER['SCRIPT_FILENAME'] instead of $_SERVER['DOCUMENT_ROOT'] to get the correct path. Note that you'll have to use dirname () or pathinfo () to strip the filename component. Link to comment https://forums.phpfreaks.com/topic/268353-how-to-get-website-root-folder-for-include/#findComment-1378105 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.