Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

require_once with subfolders [closed]

I have Folder Home with two subfolders like the following

+Home  
 +include  
   - membersite_config.php

+iDiscover  
   -index.php

in index.php I added the require_once script to access membersite_config.php

<?PHP

require_once($_SERVER['DOCUMENT_ROOT'].'/include/membersite_config.php');
?>

I get the following error : Warning: require_once(./include/fg_membersite.php): failed to open stream: No such file or directory in D:\Home\include\membersite_config.php on line 2
Fatal error: require_once(): Failed opening required './include/fg_membersite.php' (include_path='.;C:\php\pear') in D:\Home\include\membersite_config.php on line 2

The error says No such file or directory while the The path "D:\Home\include\membersite_config.php" is correct . When I move index.php to be under the root , the page works well.

I also tried to use the following code as described here but it gives the same error

<?PHP


define('ROOT', 'D:Home\\');
require_once(ROOT ."/include/membersite_config.php");
?>

Edit :

I too tried require_once("../include/membersite_config.php"); And it gives the same error

Thanks in advance

like image 680
Mariam Avatar asked Feb 24 '13 07:02

Mariam


1 Answers

You must include like this

require_once(dirname(__FILE__) . '/include/membersite_config.php');

Because DocumentRoot can be not set in httpd.conf

like image 163
Winston Avatar answered Sep 28 '22 03:09

Winston