tags:

views:

48

answers:

2

Hi,

This question should be pretty simple. I have a php file in a directory that contains function calls to read files in that directory. I need to be able to access those functions and call them from outside the directory. Is there a way to make php execute those functions relative to the file that they are physically in vs the file they were included into? If not, how would I make sure that I could read those files from different parts of the directory structure?

Thanks

A: 

So if I understand well you have something like that:

function processDir() {
    if ($dh = opendir('.')) {
        while (($file = readdir($dh)) !== false) {
            // some processing
        }

        closedir($dh);
    }
}

so why don't you path the directory to treat to your processing function in my example: function processDir(aDir)

RC
+2  A: 

__FILE__ is the name of "this" file, even if it is included somewhere else

http://us3.php.net/manual/en/language.constants.predefined.php

so fopen(dirname(__FILE__) . '/blah') will open the file from the same directory

stereofrog