htetnaing Posted July 30, 2010 Share Posted July 30, 2010 Hi everyone, This is driving me crazy. I need to reference different files located in different folder structure. For example, I have the following file structure. /my_project/ /my_project/database/database_script.php /my_project/index.php 1. If I want to reference /my_project/index.php from /my_project/database/database_script.php, how can I reference it ? 2. From /my_project/index.php to /my_project/database/database_script.php , it's obvious all I gotta do it include("/database/database_script.php"). I use $_SERVER('DOCUMENT_ROOT"), to solve the 1. problem. It works on my XAMPP local machine but when I uplode it onto the server, there's a problem. The path becomes '/my_project/my_project/database/database_script.php". Is there a universal way (more like a standard way) to reference files in php so that I won't need to change every file path once I upload those onto the server ? Regards, Quote Link to comment Share on other sites More sharing options...
onlyican Posted July 30, 2010 Share Posted July 30, 2010 First thing is echo your $_SERVER['DOCUMENT_ROOT']; Then work from there so if DOCUMENT_ROOT is /my_project/ then you want include($_SERVER['DOCUMENT_ROOT'].'/index.php'); Quote Link to comment Share on other sites More sharing options...
htetnaing Posted July 30, 2010 Author Share Posted July 30, 2010 What can i say ? Thanks a lot. Simple yet effective. I never thought of that. 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.