Php require_once does not work the way I want. Relative path

I'm having trouble assigning a relative path to require_once. I am sure that this is something simple that I do not see ...

Folder Directory Structure

Level 1: Site Level 2: Enable Level 2: Class

so ... site / include / global.php <- here the autoload function is called site / class / db.php

when i try to use

function__autoload($className)
{
     require_once '../class/'.$className.'.php';

}

I get:

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

Fatal error: require_once () [function.require]: Failed to open "../class/db.php" (include_path = '.; ../ includes; ./ pear')

? , global.php , , , .

+3
2

require(_once) include(_once) script, .. script, .

require - ,

dirname(__FILE__)."/path/to/file";

@Arkh , PHP 5.3

__DIR__."/path/to/file";
+10

( apache, )

require_once($_SERVER['DOCUMENT_ROOT'] . '/class/' . $classname '.php');
0

Source: https://habr.com/ru/post/1732578/


All Articles