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, Link to comment https://forums.phpfreaks.com/topic/209320-how-to-reference-to-a-file-in-different-location/ 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'); Link to comment https://forums.phpfreaks.com/topic/209320-how-to-reference-to-a-file-in-different-location/#findComment-1093000 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. Link to comment https://forums.phpfreaks.com/topic/209320-how-to-reference-to-a-file-in-different-location/#findComment-1093009 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.