If the index.php
is in the root of your project, the subfolders should call it ../index.php
. If it is the subfolder of a folder, then it would be ../../index.php
and so on. If the prefix ../
in the path means "upload a directory" then you must apply it as many times as depth levels of each file.
- raíz del proyecto (require 'index.php')
- ejemplo2 (require '../index.php')
- ejemplos2_corregidos (require '../..index.php')
- guia2 (require '../index.php')
This method is practicable if you have few directories and few files. As a project grows it is easier to have few entrypoints and have them define a constant by setting the fixed index route for all the other scripts that are loaded in a request. For example, in a file _bootstrap.php
include:
<?php
define('HOMEDIR',__DIR__);
And that way, in any other script that is included, you would call index.php like:
<?php
require(HOMEDIR.'/index.php');
For this to work, you would have to make every visit start from the same entrypoint that in turn redirected it to the script that you were really looking for using a parameter. In your case, the same index.php could be that entrypoint.