0

This is my app. root:

htdocs

    core/

        init.php

    classes/

        DB.php
        POST.php

    ajax/

        post_feeds.php

This is my post_feeds.php;

require_once '../core/init.php';

The file init.php is there but I don't understand why I am getting this error.

Warning: require_once(classes/DB.php): failed to open stream: No such file or directory in C:\Apache24\htdocs\core\init.php on line 9

Fatal error: require_once(): Failed opening required 'classes/DB.php' (include_path='.;C:\php\pear') in C:\Apache24\htdocs\core\init.php on line 9

It gives me no error in my init.php file when I require_once 'classes/DB.php';

This is init.php

session_start();

date_default_timezone_set('Etc/GMT+2');
//date_default_timezone_set('Europe/Tirane');

//autoload for classes.
require_once 'classes/DB.php';
require_once 'classes/USER.php';
require_once 'classes/NOTIFICATION.php';

if (isset($_COOKIE["user_id"])) {
    $_SESSION['user_id'] = $_COOKIE['user_id'];
}
2
  • 2
    Can you post the contents of init.php? If you have require_once('classes/DB.php') in init.php, then it's searching for core/classes/DB.php. Commented Jun 29, 2014 at 12:40
  • No because it loads like this: htdocs/classes/DB.php This works in my whole app. except htdocs/ajax/post_feeds.php Commented Jun 29, 2014 at 21:11

2 Answers 2

3

Try to use an absolute path for including files:

$root = realpath($_SERVER["DOCUMENT_ROOT"]);
require_once("{$root}/core/init.php");

Or with dirname:

require_once(dirname(__FILE__) .'/../core/init.php');
Sign up to request clarification or add additional context in comments.

1 Comment

It worked. Thank you. I used this: require_once (DIR .'/../classes/DB.php');
1

You dont have problem with including init.php, you have problem with init.php on line 9:

Warning: require_once(classes/DB.php): failed to open stream: No such file or directory in C:\Apache24\htdocs\core\init.php on line 9

Open init.php and change your path on line 9 from require_once('classes/DB.php') to require_once('../classes/DB.php').

DB.php is in classes folder in your root, and in line 9 on init.php you are including ROOT/core/classes/DB.php.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.