0

I created a file that I am wanting to use throughout the entirety of my site. This file is using a config file. The reason for my question is that I am not sure how to call the config file from sub-folders and the root files while just having this one file.

I understand that if I am in the same folder as the file that I call it like this:

require_once 'config.php';

And if I am in a sub-folder, I call it like this:

require_once '../config.php';

However, with this being one file, I need one cohesive method to call the file.

I tried the following, but received errors.

require_once '/home/{user}/config.php';

Errors:

Warning: require_once(/home/{user}/config.php): failed to open stream: No such file or directory in /home/domain/public_html/3dpdf.php on line 5

Fatal error: require_once(): Failed opening required '/home/{user}/config.php' (include_path='.:/opt/cpanel/ea-php71/root/usr/share/pear') in /home/domain/public_html/3dpdf.php on line 5

Does anyone know how I can use the require_once method to get the config file within my files regardless of what folder it is in?

Here is an img to help show my file hierarchy. The rectangle boxes are where I will be requiring the config file. The star is next to the config file.

enter image description here

Madhur Bhaiya
  • 28,155
  • 10
  • 49
  • 57
Paul
  • 3,348
  • 5
  • 32
  • 76
  • why dont you simply include it in your index.php so that it is available to everything else. I am assuming that index.php will always be starting point for your project – Madhur Bhaiya Sep 10 '18 at 17:13
  • No, the other files may be used as landing pages for specific mediums. – Paul Sep 10 '18 at 17:16
  • Number of landing pages will be less than trying to require_once in various other files. So you can still require in landing pages directly. – Madhur Bhaiya Sep 10 '18 at 17:20
  • The files will only be required in the file that it is needed. I would just rather not have two versions of the file I created for this project. The file that I created that will be receiving the config file is the 3Dpdf file...it will be nested within the index and solution sub-folder files. – Paul Sep 10 '18 at 17:40

0 Answers0