0
votes

I am trying to include a file in a PHP script using a relative path. However, the function returns an error stating that the file doesn't exist.

It does exist - I have attached a file structure screenshot too - and other pages can include it without issue.

Code

require_once("../config.php");

Output

Warning: require_once(../config.php): failed to open stream: No such file or directory in /www/sites/c84/7de/example.com/web/inc/sections.php on line 25

Fatal error: require_once(): Failed opening required '../config.php' (include_path='.:/usr/share/php:/usr/share/pear') in /www/sites/c84/7de/example.com/web/inc/sections.php on line 25

File Structure Screenshot

File Structure Screenshot

1

1 Answers

2
votes
/www/sites/c84/7de/example.com/web/inc../config.php

requires a / after inc and before ..

/www/sites/c84/7de/example.com/web/inc/../config.php

so something like

require_once(__DIR__ . '/../config.php');