paulherron Posted July 5, 2006 Share Posted July 5, 2006 Hi everyone. I'm trying to parse a .ini file called "site_config.ini". If I put it in the same directory as the executing script I have no problems with the following code:[code]$ini_filename = 'site_config.ini';// Read .ini file if it is present. $ini = parse_ini_file($ini_filename, false);[/code]However, if I expand this code to point to a different directory...[code]$ini_path = 'http:www.mydomain.com/includes/';$ini_filename = 'site_config.ini';// Read .ini file if it is present. $ini = parse_ini_file($ini_path.$ini_filename, false);[/code]... I get an error: "Warning: parse_ini_file(): Cannot open 'http://www.mydomain.com/includes/site_config.ini' for reading in /home/blah/blah/".I know the file is present in that directory because I can navigate to it.Putting both the path and the filename together in the same variable doesn't seem to work either.Any ideas? Link to comment https://forums.phpfreaks.com/topic/13738-parse_ini_file-absolute-link-problem/ Share on other sites More sharing options...
kenrbnsn Posted July 5, 2006 Share Posted July 5, 2006 Do not use a URL to access a file on the same domain as your script. If the INI file is in a directory that is in the same directory as the script, just do[code]<?php$ini_file = 'includes/site_config.ini';$ini = parse_ini_file($ini_file);?>[/code]Ken Link to comment https://forums.phpfreaks.com/topic/13738-parse_ini_file-absolute-link-problem/#findComment-53355 Share on other sites More sharing options...
paulherron Posted July 5, 2006 Author Share Posted July 5, 2006 That's great, thanks Ken! Am I right in saying that using external URLs is a bad idea anyway because it slows the processing down significantly?The includes folder is actually on the same level as the directory containing the script, so I got it working with:[code]<?php$ini_file = '../includes/site_config.ini';$ini = parse_ini_file($ini_file, false);?>[/code]I then developed that to the following to allow the code to work no matter what directory level it's placed at:[code]<?php$ini_file = $_SERVER['DOCUMENT_ROOT'].'/includes/site_config.ini';$ini = parse_ini_file($ini_file, false);?>[/code] Link to comment https://forums.phpfreaks.com/topic/13738-parse_ini_file-absolute-link-problem/#findComment-53389 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.