Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

273
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda