开发者

Call a method from an included file NOT from file that inclued it php

开发者 https://www.devze.com 2022-12-08 10:18 出处:网络
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 cal

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)

0

精彩评论

暂无评论...
验证码 换一张
取 消