Directory handling

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
caladbolg
Forum Newbie
Posts: 5
Joined: Thu Nov 25, 2004 10:45 pm

Directory handling

Post 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.
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post 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
caladbolg
Forum Newbie
Posts: 5
Joined: Thu Nov 25, 2004 10:45 pm

Post 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...
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post 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?
caladbolg
Forum Newbie
Posts: 5
Joined: Thu Nov 25, 2004 10:45 pm

Post by caladbolg »

I don't know the exact numbers, but they're fairly recent, Apache 2 and PHP 5
Post Reply