opendir and current path problem ?

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View

I hope my problem is easy to fix, I'm pretty new with php - but I am
getting weird results with the opendir() function.  It may just be a
path problem, but I don't see which variable to change.

here are some tests I did to see what was wrong:

    $blah = opendir("blocks");
    while ($file = readdir($blah)) {
        writelog("$file", DEBUG);

    $blah = opendir("modules");
    while ($file = readdir($blah)) {
        writelog("$file", DEBUG);

    $blah = opendir("images");
    while ($file = readdir($blah)) {
        writelog("$file", DEBUG);

In the 1st and 3rd while()'s, it correctly picks the "blocks" and
"images" directories of my doc_root path (which is the path I get when
I try a getcwd()).  However, the second while() lists me the files
contained in the "modules" directory of my server root (apache's
modules directory) instead of picking the "modules" directory in the
current dir.  (both apache and the doc_root contain a 'modules'
directory).  I know I could probably get around the problem using full
paths, but this is from phpnuke, so I'd like to keep the original code
intact and would prefer changing a config somewhere if possible.

Note that the very same server configuration on a win2k or on a winxp
do not give this problem, so I'm guessing it's a NT-related problem.
It's as if it's checking a list of directories in a path instead of
the current directory and the server_root happens to come before

Bug or feature ?  Configuration problem ?



Re: opendir and current path problem ?

Just a thought, try renameing that directory to something more random
and see if you still get the same result... it may be the choice of
"modules" as a directory name that is confusing it.

Re: opendir and current path problem ?

I already tried creating a "images" directory in apache's root
directory (same place where the 'modules' directory is) and put some
random files in it - I reloaded the page and this time it listed the
newly created "images" directory instead of phpnuke's. So it's a
question of identical directory names and paths, not just for the name

Thanks anyway ;)

On 23 Aug 2005 08:10:09 -0700, wrote:

Quoted text here. Click to load it

Re: opendir and current path problem ?

Take a look at your include path in php.ini.  It may be looking in ./,
then ../, then elsewhere.  What happens when you specify the complete
path to the directory in your call to opendir() ?

Re: opendir and current path problem ?

Hi, sorry for the delay...

Putting the full paths work, as I expected.
My php.ini include path is:
include_path = ".;C:\apachefriends\xampp\php\pear\"

The . is the current directory I think, though logically that would be
apache\bin rather than apache\.  However, as I said,  this very same
configuration does not give me the problem on a Win2k/XP machine.  So
I figure it's WinNT that's being weird here.

For now I think I will simply move the site on a different server
rather than waste time modifiying code - it's just a few lines to fix,
but who knows what other surprises this kind of problem might give me

Anyway, if anyone sees where the bug is, feel free to join in..




Quoted text here. Click to load it

Site Timeline