Require_once with subfolders

I have a Home folder with two subfolders like

+Home +include - membersite_config.php +iDiscover -index.php 

in index.php I added a require_once script to access memberite_config.php

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

I get the following error: Warning: require_once (./include/fg_membersite.php): could not open the stream: there is no such file or directory in D: \ Home \ include \ membersite_config.php on line 2
Fatal error: require_once (): opening failure required "./include/fg_membersite.php" (include_path = '; C: \ php \ pear') in D: \ Home \ include \ membersite_config.php on line 2

The error says: There is no such file or directory as long as the path "D: \ Home \ include \ membersite_config.php" is correct. When I move index.php to the root, the page works well.

I also tried using 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 also tried require_once ("../include / membersite _config.php"); And he gives the same error

Thank you in advance

+4
source share
7 answers

You must include this as

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

Since DocumentRoot cannot be installed in httpd.conf

+3
source

The error means that you have a requirement in membersite_config.php that does not work on line 2.

+1
source
 require_once(dirname(dirname(__FILE__)).'/home/include/membersite_config.php'); 
+1
source

Try the following:

 require_once("../include/membersite_config.php"); 

Do not forget to check the rights to the file / folder!

0
source

Try the following:

 <?PHP require_once('../include/membersite_config.php'); ?> 
0
source

'..' means back

require_once ('../include / membersite _config.php');

means you selected the folder you are in, then type include ...

if you need to exit three folders do it ../../../ enable ... etc

0
source

To debug, try the following:

 <?php $dir_files=glob($_SERVER['DOCUMENT_ROOT'].'/include/*'); print_r($dir_files); ?> 

after running this script, you will see if your file names are specified correctly.

0
source

All Articles