Page 1 of 1

Directory handling

Posted: Fri Nov 26, 2004 5:29 pm
by caladbolg
Sorry, I have another problem. Running Apache 2 in windows, I come across a problem that is absent when running Apache 2 in linux.

I have a folder called 'scripts' in the root directory and then a file called 'functions.php' in the 'scripts' folder.

root (htdocs)
|scripts
|--functions.php

(And of course there are other files in the root directory including index.php)

In functions.php, I have lines that call several other files in the 'scripts' folder. They are called out like:

Code: Select all

require('scripts/file1.php');
require('scripts/file2.php');
require('scripts/file3.php');
...
Now in Windows, when I call upon index.php, there is a function that calls functions.php to execute (with all the code inside) and when it gets to the code listed above in functions.php, it returns a "file not found" error. I assume it is looking for the file:

Code: Select all

root/scripts/scripts/file1.php
instead of

Code: Select all

root/scripts/file1.php
In linux I do not have this problem and everything functions properly.

Anybody know why this happens and what I can do to fix it? Thanks.

Posted: Mon Nov 29, 2004 7:29 pm
by rehfeld
i really have no clue why it would act diff on nix and win, unless the php include dir is coming into play here(unlikely)

my guess would be that the file really doesnt exist, but im sure youve checked that

to avoid problems like this, espescially if you reorganize things later down the road, something like this can help

Code: Select all

require($_SERVER['DOCUMENT_ROOT'] . '/path/to/script.php');
that way you can write your includes based on a path that will not change if your in a file thats not in the doc root.

you can even take it a step farther:

Code: Select all

// in a config file, or at the top of the script
define('INCLUDES', $_SERVER['DOCUMENT_ROOT'] . '/path/to/includes/');


// the in the rest of the script you can just

require(INCLUDES . 'script.php');
hope that helps

Posted: Wed Dec 01, 2004 3:05 pm
by caladbolg
I really appreciate you taking time to help me out. I will do that next time. Thanks a lot :)

But if anyone else knows how to fix the problem...

Posted: Wed Dec 01, 2004 3:39 pm
by rehfeld
try doing this on both servers and see if it returns something that looks like it could be related

Code: Select all

echo ini_get('include_path');
if it doesnt look related, what versions of apache and php are on your win and linux boxes?

Posted: Wed Dec 01, 2004 6:19 pm
by caladbolg
I don't know the exact numbers, but they're fairly recent, Apache 2 and PHP 5