7

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

Community
  • 1
  • 1
Mariam
  • 429
  • 2
  • 7
  • 13

7 Answers7

5

You must include like this

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

Because DocumentRoot can be not set in httpd.conf

Winston
  • 1,758
  • 2
  • 17
  • 29
1

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

yunzen
  • 32,854
  • 11
  • 73
  • 106
  • I can see that it doesn't work. It says failed to open stream: No such file or directory , while the directory do exists. That's why I am asking whats wrong in my code – Mariam Feb 24 '13 at 07:45
  • 1
    Read what I typed. The error is not in the index.PHP. – yunzen Feb 24 '13 at 10:43
  • index.php can't access membersite_config.php , when it's inside the subfolder iDiscover. When I move index.php to the root. the same code works with no problems. – Mariam Feb 24 '13 at 11:49
1
require_once(dirname(dirname(__FILE__)).'/home/include/membersite_config.php');
Igor Jerosimić
  • 13,621
  • 6
  • 44
  • 53
Ankit Agrawal
  • 6,034
  • 6
  • 25
  • 49
0

Try this:

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

don't forget to check the file/folder permissions!

One Man Crew
  • 9,420
  • 2
  • 42
  • 51
  • Thanks. I tried it but it gives the same error . The file folder permission is full control. And I can access the file when I move index.php to the root instead of putting it inside iDiscover folder – Mariam Feb 24 '13 at 07:31
0

Try this:

<?PHP
require_once('../include/membersite_config.php');
?>
richard
  • 1,456
  • 4
  • 15
  • 22
0

'..' means back

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

means get out the folder you are in, then enter include...

if you have to get out three folders do this ../../../include... etc.

Abdullah Salma
  • 560
  • 7
  • 20
0

For debugging try this:

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

after you run this script, you will see if your filename(s) are correct.

Stef Geysels
  • 1,023
  • 11
  • 27