Jump to content

require_once(classes/Config.php): failed to open stream


Dianbr

Recommended Posts

Hi,

 

I hope someone can help. I am fairly new to php and have the following problem that I cannot get a solution for.

 

We are building a logon system for a website and are receiving the following error.

 

?>PHP Warning: require_once(classes/Config.php): failed to open stream: No such file or directory in C:\Domains\hellopoker.co.za\wwwroot\test\php\core\init.php on line 22 PHP Fatal error: require_once(): Failed opening required 'classes/Config.php' (include_path='.;C:\php\pear') in C:\Domains\hellopoker.co.za\wwwroot\test\php\core\init.php on line 22

 

 

Code for index.php

 

<?php

require_once 'core/init.php';

echo Config::get('mysql/host');

?>
 

Code for config.php

 

<?php

class Config{
    public static function get ($path = null){
        if ($path){
            $config = $GLOBALS['config'];
            $path = explore('/',$path);
            
            foreach($path as $bit){
                if(isset($config[$bit])){
                    echo 'Set';
                }
            }
        }
    }

}

?>

 

 

Code for init.php

 

 

<?php

session_start();

$GLOBALS['config'] = array(
    'mysql' => array(
        'mysql' => 'xxxxxxx',
        'username' => 'xxxxxx',
        'password' => 'xxxxxxx',
        'db' => 'xxxxxxx'
        ),
        'remember' => array(
            'cookie_name' => 'hash',
            'cookie_expiry' => 604800
        ),
        'session' => array(
            'session_name' => 'user'
        )
);

spl_autoload_register(function($class) {
    require_once 'classes/' . $class . '.php';
});

?>



?>

 

 

Any help will be greatly be appreciated.

 

 

Use relative URLs, depending on where the classes directory lies in your structure, you could do the following:

spl_autoload_register(function($class) {
    require_once ($_SERVER['DOCUMENT_ROOT'] . '/classes/' . $class . '.php');

});

 

From your error you can see that your autoloader can't find the file to include.

Hard to follow this bunch of code, but the error is pretty self-explanatory.  You are trying to find a file that is just where you think it is.  The message pinpoints the line with the problem, use the info provided to check your file system to see that the reference is accurate.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.