eevan79 Posted July 9, 2010 Share Posted July 9, 2010 How to include file from subdirectory? I have tried include '../config.php'; but got error selecting database. Also tried include($DOCUMENT_ROOT."../config.php"); but same result. For example, I have "root/admin" directory, and cant connect (from "/admin" dir) to database config.php which is in root.There are also other files to include. Link to comment https://forums.phpfreaks.com/topic/207270-include-root-file-from-subdirectory/ Share on other sites More sharing options...
Pikachu2000 Posted July 9, 2010 Share Posted July 9, 2010 $_SERVER['DOCUMENT_ROOT'], not $DOCUMENT_ROOT Link to comment https://forums.phpfreaks.com/topic/207270-include-root-file-from-subdirectory/#findComment-1083698 Share on other sites More sharing options...
eevan79 Posted July 9, 2010 Author Share Posted July 9, 2010 No such file or directory...\adm\admin.php on line 2 I use this code: include($_SERVER['DOCUMENT_ROOT']."../config.php"); How to back one level? Link to comment https://forums.phpfreaks.com/topic/207270-include-root-file-from-subdirectory/#findComment-1083704 Share on other sites More sharing options...
BizLab Posted July 9, 2010 Share Posted July 9, 2010 You need to locate that file first... go into dreamweaver (if you have it) and physically find the file. Without a GOOD filepath, we can't help you locate the file. Also, you don't include the "../" when using the $_SERVER['DOCUMENT_ROOT'] function. you are already at the root of the site. so $_SERVER['DOCUMENT_ROOT'] essentially equals www.your-domain.com you can't back up beyond that (well.. not entirely true - but you shouldn't be doing that =^) ). SO: i would just try require(' $_SERVER['DOCUMENT_ROOT']./config.php') which will drop you in the site root.. the same place as your index (homepage). Link to comment https://forums.phpfreaks.com/topic/207270-include-root-file-from-subdirectory/#findComment-1083707 Share on other sites More sharing options...
eevan79 Posted July 9, 2010 Author Share Posted July 9, 2010 I already tried that: include($_SERVER['DOCUMENT_ROOT']."./config.php"); and include($_SERVER['DOCUMENT_ROOT']."config.php"); and many other combinations...but it wont work. That path is on/from localhost. Didnt tested online. I need to locate path automaticly if its possible. For example to get working directory and go back one level. Is it possible (like in java or c++)? Link to comment https://forums.phpfreaks.com/topic/207270-include-root-file-from-subdirectory/#findComment-1083718 Share on other sites More sharing options...
wildteen88 Posted July 9, 2010 Share Posted July 9, 2010 Seems your server isn't setup quite right. Whats path is returned when you echo out $_SERVER['DOCUMENT_ROOT'] echo $_SERVER['DOCUMENT_ROOT']; $_SERVER['DOCUMENT_ROOT'] should echo the path to the folder where you place all your files for your site which is served by your http server, eg for Apache it maybe C:/Apache/htdocs, or if you're using IIS most probably C:/Innetpub/public. Can you tell us where your config.php file is located (post full file path)? Link to comment https://forums.phpfreaks.com/topic/207270-include-root-file-from-subdirectory/#findComment-1083724 Share on other sites More sharing options...
eevan79 Posted July 9, 2010 Author Share Posted July 9, 2010 Now its working. Code is include("../config.php"); I just added "(" and ")"... :-\ include("../config.php"); Link to comment https://forums.phpfreaks.com/topic/207270-include-root-file-from-subdirectory/#findComment-1083728 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.