致命错误 - Require_once

I am getting the following error:

Warning: require_once(C:\xampp\htdocs\mvc\public\views\home\init.php): failed to open stream: No such file or directory in C:\xampp\htdocs\mvc\public\index.php on line 3

Fatal error: require_once(): Failed opening required 'C:\xampp\htdocs\mvc\public\views\home\init.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\mvc\public\index.php on line 3

In Index.php, my code is

<?php
require_once __DIR__ . '\views\home\init.php';
$app= new app;
?>

In init.php, my code is

<?php require_once __DIR__ . '\core\app.php';
 require_once  __DIR__ . '\core\controller.php';

In controller.php:

<?php
class controller
{
}
?>

In app.php

<?php
class app
{
public function _construct() 
{
    echo 'now what';
}
}
?>

My folder paths are:

htdocs\mvc\app\views\home\init.php

htdocs\mvc\app\core\app.php & controller.php

htdocs\mvc\public\index.php

Anybody please help? i have tried require_once (_DIR . ""); as well but not working.

Try this:

First do echo for the file path in index.php file like -

echo __DIR__ . '/views/home/init.php';

And then check whether the path is correct or not. If not, then change it accordingly and then use the path in require_once.

You can also test the permission of directory and file itself. There could be an issue of executing file if permission is read only.

restore the index.php file in your public folder.... the error will clear out.

Put index.php file in your public folder.... the error will clear out.

tested and verified