PHP file_exists and wildcard

后端 未结 4 1266
孤街浪徒
孤街浪徒 2020-12-03 00:20

Is there a way to write the PHP file_exists function so that it searches a directory for a file with an arbitrary extension. For instance, suppose I knew that a file were c

4条回答
  •  悲哀的现实
    2020-12-03 00:51

    As long as file_exists returns a BOOLEAN I wrote this small function that accepts a search string with * to look for files... Example:

        searchForFile("temp*");
    
        function searchForFile($fileToSearchFor){
            $numberOfFiles = count(glob($fileToSearchFor));
            if($numberOfFiles == 0){ return(FALSE); } else { return(TRUE);}
        }
    

提交回复
热议问题