2012-06-25 120 views
0

我工作的一个PHP项目,我得到的require_once错误(或者甚至需要)致命错误:require_once()(include_path中= '; C: PHP5 梨')

Warning: require_once(C:/wamp/www/MyFiles/MyProject/includes/db_config.php) [function.require-once]: failed to open stream: No such file or directory in C:\wamp\www\MyFiles\MyProject\includes\autoloads.php on line 9 

Fatal error: require_once() [function.require]: Failed opening required 'C:/wamp/www/MyFiles/MyProject/includes/db_config.php' (include_path='.;C:\php5\pear') in C:\wamp\www\MyFiles\MyProject\includes\autoloads.php on line 9 

这就是我如何包括

$root = $_SERVER['DOCUMENT_ROOT']; 
//config.. 
require_once($root . '/MyFiles/MyProject/includes/db_config.php'); 

我一直在使用

echo $root . '/MyFiles/MyProject/includes/db_config.php'; 

在打印网址正确

试图文件

C:\wamp\www\MyFiles\MyProject\includes\db_config.php

我使用WAMP服务器5 autload.php和db_config.php都在同一个文件夹

+2

你肯定**文件('db_config.php')在那个目的地吗? – 2012-06-25 11:12:58

+0

是的文件位于相同的路径 –

+0

我是否需要在PHP.ini中进行任何配置? –

回答

0
  1. 试试这个要求建设

    require 'file';

  2. ..或此根设置

    $root = realpath($_SERVER['DOCUMENT_ROOT']);


update use virtual host


+0

仍面临着同样的错误:( –

+0

@SyedSalmanRazaZaidi您是否尝试过删除路径中的空格? – treng

+0

没有空格的路径 –

0

是文件的可读性?

试试这个:

<?php 
echo "Does file exist?". file_exists($file) ? 'true' : 'false'; 
echo "Is it readable?".is_readable($file) ? 'true' : 'false'; 
require_once $file; 

您也可以使用相对路径来你在文件中,而不是依靠DOCUMENT_ROOT字符串:

<?php 
$root = realpath(dirname(__FILE__)); 

此外,该目录分开在windows默认情况下是\,而不是/(即使对于要求,alltough /也应该解析)。有预定的常数,您可以使用,只是为了确保它是兼容的无处不在,但:

require_once($root . DIRECTORY_SEPARATOR . 'MyFiles' . DIRECTORY_SEPARATOR . 'MyProject' . DIRECTORY_SEPARATOR . 'includes' . DIRECTORY_SEPARATOR . 'db_config.php'; 

此外,如果你正在使用APC缓存,可以尝试重新启动它,如果有该文件的一个过时的高速缓存。 (E.G filemtime不正确)

+0

感谢回复乔恩,这两个语句都打印真实,但reuquire_once此代码给出相同的错误:( –

0

仔细检查服务器上是否存在文件。如果你不能不管出于什么原因,这将做到这一点:

if(file_exists($myFile)){ 
echo"The file is there"; 
}//end of file exists 
else{ 
echo"the file does NOT exist....fool"; 
}//end of else - the file is not there 

这是我能想到的唯一的问题 - 该文件是不是它应该是...试试上面,并让我了解。

+0

是它的打印文件有 –

0

也可能是一个问题,目录分隔符在Linux和Windows机器上不同。 也许尝试使用常量DIRECTORY_SEPARATOR而不是硬编码分隔符?

+0

顺便说一句,如果你说'echo $ root。'/MyFiles/MyProject/includes/db_config.php ';'在你的代码中,它回应'C:\ wamp \ www \ MyFiles \ MyProject \ includes \ db_config.php'我认为你的斜线和反斜杠可能有问题 –

0

检查文件是否存在,如果存在,请检查文件的权限。

+0

是的,我试过检查文件的存在和它存在 –

相关问题