PHP includes the file. Show error file not found

I am using the include function and it gives errors. This file was not found. In the root directory I have - index.php and config.php

index.php includes config.php and has some other data.

config.php contains database information and includes the /function.php function

There is a user of the folder and has the calculate.php file in calculate.php. I turned on the AJAX function, and the file is loaded into it by an AJAX call. The file is cal2.php and is located in the user folder . Now this cal2.php has an include function for config.php , for example:

include "../config.php";

When this cal2.php is loaded from calculate.php

File

function / function.php is not loaded. It shows that the file was not found for function function / function.php

So the file structure:

  • root
  • /index.php
  • /config.php
  • /user/calculate.php
  • /user/cal2.php
  • /function/function.php

How to proceed and not have a .php function enable error for cal2.php

+3
source share
3 answers

You must modify config.php to use the absolute path to functions.php. If you have PHP 5.3 or higher, do it like this:

include(__DIR__.'/functions/functions.php');

If you are still using PHP 5.2 (or, God forbid, something earlier), you can do this as follows:

$dir = dirname(__FILE__);
include($dir.'/functions/functions.php');

__FILE__ PHP, dirname(__FILE__) script.

+4

:

$_SERVER['DOCUMENT_ROOT'].'/function/function.php'
0

All problems here

/user/cal2.php
/function/function.php

you need to enable this way:

include('../config.php');

BUT I had this problem and I suggest that you include the files in the header of each page. The configuration you must include in the title of each page.

Read this, think it helps:

problems with global variables

-1
source

Source: https://habr.com/ru/post/1781093/


All Articles