I got a problem with this:
I got file xxx.php in which I’m parsing one file: $config[‘etc’] = parse_ini_file(‘config/config.txt’);
Everything is fine, until I’m including xxx.php file to my yyy.php file using require_once("lang.inc.php");
Then I get an message: Warning: parse_ini_file(config/config.txt): failed to open stream: No such file or directory in …
When I change ;
$config[‘etc’] = parse_ini_file(‘config/config.txt’);
to
$config[‘etc’] = parse_ini_file(‘../config/config.txt’);
then my yyy.php works fine, but xxx.php not… and I’m in stuck.
Help me guys, please.
Try using absolute file paths if your PHP scripts can be invoked (or requested) from different directories. For example, the current directory of a PHP script executed under
example.com/one.phpwill be different fromexample.com/folder/two.php.Your change to
is still relative, except this time it’s just “one directory up from the current directory > config > config.txt”, rather than before, where you were looking in the same current directory.
A generic fix would be to do the following:
There are possible issues with using the
DOCUMENT_ROOTfield, but it should be fine for the most part (such asDOCUMENT_ROOTnot being defined under the CLI). Also, check ifDOCUMENT_ROOThas a trailing slash, even though the standard is not to have it, some hosts may have the trailing slash included. If it does, remove your slash at the beginning of your file path.