Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

271
Views
How to access correctly classes from directories/subdirectories?

When I try to access includes/config.php from inside account/index.php I get these errors:

Warning: include(classes/user.php): failed to open stream: No such file or directory in /var/www/htdocs/dashboard/includes/config.php on line 6

Warning: include(): Failed opening 'classes/user.php' for inclusion (include_path='.:/usr/share/php') in /var/www/htdocs/dashboard/includes/config.php on line 6

I define the path correctly, but when index.php access to config.php, I think config.php occurs directory problem when calling classes in config.php, I couldn't find how to solve it.

Thanks in advance.

Here is folder structure

App/
├─ account/
│  ├─ index.php
├─ classes
├─ includes/
│  ├─ config.php
├─ index.php

index.php in account/index.php

<?php
require('../includes/config.php');
?>

config.php in includes/config.php

<?php
ob_start();
session_start();

//include the user class, pass in the database connection
include('classes/user.php');
include('classes/phpmailer/mail.php');
include('classes/slug.php');
$user = new User($db);
?>
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

As @Sohrab said you need give it absolute path. You can achieve this problem with __DIR__. (the directory of the file) to Learn more about DIR

You should use it like:

require(__DIR__.'/../includes/config.php');

also in config.php and other files:

include(__DIR__.'/../classes/user.php');
include(__DIR__.'/../classes/phpmailer/mail.php');
include(__DIR__.'/../classes/slug.php');
over 4 years ago · Santiago Trujillo Report

0

Config file looks for the files in its directory. You should change your code to:

<?php
ob_start();
session_start();

//include the user class, pass in the database connection
include('../classes/user.php');
include('../classes/phpmailer/mail.php');
include('../classes/slug.php');
$user = new User($db);
?>
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!