-1

I am working on a PHP project,i am getting an error in require_once(or even in require)

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

this is how i am including the file

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

i have tried using

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

It is printing URL properly

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

I am using WAMP server 5 autload.php and db_config.php are in same folder

Syed Salman Raza Zaidi
  • 2,172
  • 9
  • 42
  • 87

5 Answers5

0
  1. Try this require construction

    require 'file';

  2. ..or this root settings

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


update use virtual host


treng
  • 1,665
  • 3
  • 15
  • 22
0

Is the file readable?

Try this:

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

You can also use path relative to the file you're in, instead of relying on the DOCUMENT_ROOT string:

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

Additionally, the directory separate in windows is by default \, not / (alltough / should resolve aswell, even for require). There's a predefined constant you could use, just to make sure it's compatible everywhere though:

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

Also, if you are using APC cache, you can attempt to restart it, if there's a stale cache of the file. (E.G filemtime is incorrect)

Jon Skarpeteig
  • 4,118
  • 7
  • 34
  • 53
0

Double check if the file exists on the server. If you can't for whatever reason, this will do it:

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

That's the only problem I can think of - the file is not where it should be... Try the above and keep me updated.

0

Might as well be a problem with the directory separator being diffrent on linux and windows machines. Maybe try using the constant DIRECTORY_SEPARATOR instead of hardcoded separators?

  • And by the way. If you say `echo $root . '/MyFiles/MyProject/includes/db_config.php';` in your code and it echoes `C:\wamp\www\MyFiles\MyProject\includes\db_config.php` I think there might be something wrong with your slashes and backslashes – Hauke Haien Jun 26 '12 at 08:05
0

check the existence of file, if exists, check the permission of file.

satdev86
  • 800
  • 7
  • 14