Reputation: 83
What is the alternate to parse the config file to give the absolute path in php.
ie) I am reading the db config file like:
$config = parse_ini_file('../../../config.ini');
I need to give the absolute path for the above like:
$_SERVER['DOCUMENT_ROOT'].'/<my_path>/config.ini';
I need to avoid the use of '../../' in my paths
If i use:
$config = $_SERVER['DOCUMENT_ROOT'].' /my_path/my_path/config.ini';
I get
Illegal string offset 'username'
Upvotes: 0
Views: 580
Reputation: 83
Ok i got it using below:
$path = getcwd().'/mypath/config.ini';
$config = parse_ini_file($path);
Upvotes: 0
Reputation: 7080
In your Root folder of the project maintain a config.php
there you can add such data. This is what followed by many PHP projects including WordPress.
For example from WordPress
define('ABSPATH', dirname(__FILE__) . '/');
They defined ABSPATH
in wp-config.php
and it holds absolute path of application. So you refer them in your application wherever you want,
In your case this could be like following.
parse_ini_file(ABSPATH. 'config.ini');
Upvotes: 1