PHP: Error while including and requesting files

I tried to create a bootstrap file, but whenever I try to include or require it in another file, this error appears:

Warning: require_once (../folder/file.php) [function.require-once]: could not open the stream: there is no such file or directory in ...

Fatal error: require_once () [function.require]: Failed to open the window "../folder/file.php" (include_path = '.:') In ...

To draw the whole scenario: I have a boot file, load.php. In it, I connect to the configuration file at .. /config/config.php. Above the boot file, I have a database class file in the /database.php classes. In the database file, I wrote this if statement:

           if ( file_exists('../load.php') ) {
               echo 'load.php: It exists';
               require_once('../load.php');
           } else {
                  echo 'load.php: It does not exist';
                  }

I wrote a similar if statement in the boot file, but I check if the configuration file exists. Surprisingly, when I load the database.php file, I get:

load.php: It exists
config.php: file doesn't exist

But when I load the load.php file, I get:

config.php: It exists

This is where my files are located:

Root directory: / Library / Web server / Documents / project

config.php file /Library/WebServer/Documents/project/config/config.php

file load.php: /Library/WebServer/Documents/project/includes/load.php

file database.php: /Library/WebServer/Documents/project/includes/classes/database.php

I need help with this error. Thank,

+5
source share
1 answer

use dirname(__FILE__) . '../relative/path/from/file/in/which/opened/to/config.php'. From PHP 5.3 there is also a __DIR__constant

+8

All Articles