Jump to content

'parse_ini_file' Absolute Link Problem


paulherron

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.