Home > other >  No such file or directory error using relative paths in php
No such file or directory error using relative paths in php

Time:02-03

I face strange problem in writing paths using function "requrire_once". There is file open file that open file that open file, Only the last got the error of "Failed to open stream: No such file or directory", which all of them have been written by the same way of writing the relative path

first file => require_once '../models/user/student.php';

second file => require_once 'user.php';

third file => require_once '../db_controller.php';

The error => Warning: require_once(../db_controller.php): Failed to open stream: No such file or directory in D:\Setup\xampp\htdocs\BOB2.1\Teacher-Assistant-SW\models\user\user.php on line 3

enter image description here

CodePudding user response:

Accroding to the error message, you were trying to call '../db_controller.php' in './models/user/user.php'. Which means the path you were calling is './models/user/../db_controller.php' => './models/db_controller.php'.

So, the error is correct, the path is not exists. I usually use root path to avoid this. =)

  •  Tags:  
  • php
  • Related