0
votes

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.

4
there has to be a problem with the file path. right now you're pointing to a file in a views directory in the same place as index.php.. is this correct?DevDonkey
It seems that your index.php is located at public/ folder, while your required file views/home/init.php is located at app/ folder. So, try require '../app/views/home/init.php'; If it doesn't work, you can try realpath (__FILE__.'../app'); to get your app/ folder's realpath name.Chu Ya'an Xiaonan
index.php is in mvc/public. View path is mvc/app/viewsAyaz
@Chu i have tried it also but its not working as well. Both, require & require_onceAyaz
@Ayaz Oh, I'm sorry. It's ../../views/home/init.php, I've forgot another ..Chu Ya'an Xiaonan

4 Answers

0
votes

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.

0
votes

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

0
votes

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

0
votes

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

tested and verified