Call a method from an included file NOT from file that inclued it php
This question should 开发者_如何学Gobe 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
__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
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)
精彩评论