问题
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
回答1:
You must include like this
require_once(dirname(__FILE__) . '/include/membersite_config.php');
Because DocumentRoot can be not set in httpd.conf
回答2:
The error means that you have a require in your membersite_config.php
that does not work on line 2.
回答3:
require_once(dirname(dirname(__FILE__)).'/home/include/membersite_config.php');
回答4:
Try this:
require_once("../include/membersite_config.php");
don't forget to check the file/folder permissions!
回答5:
Try this:
<?PHP
require_once('../include/membersite_config.php');
?>
回答6:
'..' 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.
回答7:
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.
来源:https://stackoverflow.com/questions/15049592/require-once-with-subfolders