|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hi PHP Experts,
I am writing a wrapper over some existing code and when I hoped that I almost successfully completed it, I ran into the wall. The wrapper file is in /var/www/sites/project/ as xyz.php and the file includes some of the files from various paths. Starting with ============== // Importing Init.php for initializing the libraries include_once("checkout/controller/Init.php"); and this Init.php in /var/www/sites/project/checkout/controller loads the configuration file and code is as below. ============================================ if(file_exists("../common/config.ini")) { $configData = parse_ini_file("../common/config.ini"); } else { $configData = false; } if (!$configData) { die("An error occurred while trying to get ". "confidential config data. Please ensure that the ". "pathname to this file in Init.php ". "is correct."); } ============================================ This config.php file is in /var/www/sites/project/common/ but there is some messup in the path and its not setting to the right path as it must looking for the file with include path set to /var/www/sites/project/ rather /var/www/sites/project/checkout(it works if I keep the xyz.php file in checkout folder. But I want this file to be in parent folder for various other reasons and I cant figure out for nuts how to make this path thing work. Thanks, Gowtham.N |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On Apr 12, 2008, at 8:28 AM, GoWtHaM NaRiSiPaLli wrote: > if(file_exists("../common/config.ini")) { > $configData = parse_ini_file("../common/config.ini"); > } else { Try changing above code so it reads if(file_exists("common/config.ini")) { $configData = parse_ini_file("common/config.ini"); } else { As the xyz.php is in /var/www/sites/project/ folder , and that is the starting path of the script so any script that needs to include /var/www/sites/project/common/someFile.php you need to specify relative path to '/var/www/sites/project/' which is 'common/someFile.php' this should work unless some of included files uses 'chdir' function that changes current directory Igor Jocic http://www.carster.us/ Used Car Classifieds |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On Sat, Apr 12, 2008 at 11:06 PM, Bojan Tesanovic <btesanovic@gmail.com> wrote:
> > On Apr 12, 2008, at 8:28 AM, GoWtHaM NaRiSiPaLli wrote: > > > > if(file_exists("../common/config.ini")) { > > $configData = parse_ini_file("../common/config.ini"); > > } else { > > > > > Try changing above code so it reads > > > if(file_exists("common/config.ini")) { > $configData = parse_ini_file("common/config.ini"); > } else { In your primary file, you could also consider adding: <?php $base_path = dirname(__FILE__); ?> And then, all includes from within that file would be included as such: <?php include($base_path.'/common/config.ini'); ?> Finally, on a different note, it may not be in your best interest to keep a .ini extension on a configuration file, since this is generally readable on the web. -- </Daniel P. Brown> Ask me about: Dedicated servers starting @ $59.99/mo., VPS starting @ $19.99/mo., and shared hosting starting @ $2.50/mo. Unmanaged, managed, and fully-managed! |
|
![]() |
| Outils de la discussion | |
|
|