如何在不知道PHP中的目录的情况下检查文件是否存在?

Is there any function that will respond whether a file exists or not without knowing its directory using PHP?

So far there are two functions in PHP is_file() and is_dir() to work with files. But this time I think these two will not working efficiently to fulfill my requirements. Why?

Suppose In the root directory of my project there are 12 sub-directories, and each sub-directories can have their own sub-directories along with other valid files.

Now I will put a file name [ only file name, not full path ] in a textbox and when I click on the search button it will return the full path if the file exists on either root_directory or any sub_directory of the root directory or the available_other_sub_directory of the subdirectory_of_root_directory.

Is it possible to do handle this by any built-in function of PHP? If yes then can anyone tell me how?

  • Thanks

There is also a glob() function PHP glob()

foreach (glob("*.txt") as $filename) {
    echo "$filename size " . filesize($filename) . "
";
}