Huligan Huligan - 5 months ago 26
PHP Question

How include file in PHP?

I have

index.php
file in directory
My
.

This file has including of file
core/coreEngine.php


Inside
coreEngine.php
I try include another file
config/test.php
that is located on the previous directory:

index.php
/core/coreEngine.php
/config/test.php


I tried all cases:

require_once '../config/test.php';
require_once '../../config/test.php';
require_once '.../config/test.php';

Answer
My/index.php
My/core/coreEngine.php <--- you are here
My/config/test.php     <--- you want to go here

You want to go back to My directory, so 2 directories back :

require_once '../../config/test.php';

BUT I strongly recommend to use absolute path instead of the relative one. You might want to use something like :

require_once($_SERVER['DOCUMENT_ROOT'].'/config/test.php');