Search code examples
phpfilepathabsolute-path

Find path to file on server using php -


I would like to know how to get the absolute file path of the file i have found using glob() function. I am able to find a desired file using

foreach (glob("access.php") as $filename) {
    echo "$filename absolutepath is:  ";
}

not sure what function gets the full path of the file searched. Tried to google but can't find anything sensible.

Thanks

Slight update : I have noticed that glob() function only searches the directory that the script is run from - and that is not good to me. I need a function that is equivalent to unix find / -name "somename"

Any alternative ? or am i missing something with the glob() ??


Solution

  • If you have to look also for files in subdirectories, you could use something like the following:

    foreach (glob("{access.php,{*/,*/*/,*/*/*/}access.php}", GLOB_BRACE) as $filename) {
        echo "$filename absolutepath is:  ".realpath($filename);
    }