skip to Main Content

I am haviing issue in including file in php

`<?php
 include "../../db/db_connection.php";`

Error

Warning: include(../../db/db_connection.php): Failed to open stream: No such file or directory in /var/www/html/practice/Blogs/actions/accounts/general.php on line 2

Here is my directories

Image for my directories

I try to check it in terminal and the file is opened normally but giving error on the localhost

2

Answers


  1. You need to use DIR, also you have only one level "../"

    include __DIR__ . '/../db/db_connection.php';
    

    But it`s better to use require_once for config files

    Login or Signup to reply.
  2. You may check you file location first, include() and its relatives take filesystem paths, not web paths relative to the document root.

    To get the parent directory use ../

    include('../db/db_connection.php');
    
    include('../../db/db_connection.php');
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search