bbc496 bbc496 - 6 months ago 62
Ini Question

parsing files outside root confusion

say i have c:\usr\local\public as my root directory. this is public and what is accessed through the url.

if i want to use ini files or anything that i dont want on the public directory and want it say in c:\usr\local\nonpublic i would use the /../nonpublic/file.ini to access it?
example:

parse_ini_file($_SERVER['DOCUMENT_ROOT'].'../nonpublic/config.ini');


i know this may be stupid as hell but im confused on how i would parse it correctly being as im still new to this.

is there also a way to make a directory in php.ini/apache.conf where it can be located and parsed this way? that way when i parse it in php i can just use the filename instead of its relative/absolute location?
example:

parse_ini_file('config.ini');


i tried googling some examples but maybe my wording for the search didnt give too many results which left me even more confused.

Answer Source

Try to set include path.

<?php
$path = 'c:\usr\local\nonpublic';
set_include_path(get_include_path() . PATH_SEPARATOR . $path);
$iniArray = parse_ini_file('config.ini');

You can set this include_path in your php.ini too, so you do not need to do the set_include_path every time.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download