-1

I am here because my php code keeps giving me this annoying error whenever i include something from a directory , or just including something from a file. The error is originating from includes.php. I later found that you have to add the COMPLETE path to the directory. So I did, but it just keeps giving me the same error.

My code:

include_once (__DIR__."/inc/defines.inc.php");
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141

1 Answers1

1

Note that __DIR__ gets replaced by the files own directory path. The issue here is most likely that the path from the script you include does not match the directory you want to include a file from.

A common practice is to have a file at the root of your project that defines the root path. If you include that config file (or whatever you call it), it is easier for you to include other files.

For example. imagine a project like this:

  • config.php
  • foo/bar.php
  • foo/baz/bat.php

Example content of config.php:

<?php
define('ROOT_PATH', __DIR__);

Now, the content of foo/baz/bat.php could be:

<?php
// Get the config file
include '../../config.php';

// Include the content of foo/bar.php
include ROOT_PATH . '/foo/bar.php';
OptimusCrime
  • 14,662
  • 13
  • 58
  • 96