fork(1) download
  1. <?php
  2. function findFile($root, $path, $filename) {
  3. $findFileAux = function($cwd, $filename) use (&$findFileAux, $root) {
  4. $file = "{$cwd}/{$filename}";
  5.  
  6. // we can't do a file_exists check on a paste, echo istead
  7. // if (file_exists($file)) return file_get_contents($file);
  8. echo $file, "\n";
  9.  
  10. if ($cwd === $root) return false;
  11. return $findFileAux(dirname($cwd), $filename);
  12. };
  13. return $findFileAux("{$root}/{$path}", $filename);
  14. }
  15.  
  16. findFile("/var/www", "foo/bar/qux", "sidebar.html");
Success #stdin #stdout 0.02s 24448KB
stdin
Standard input is empty
stdout
/var/www/foo/bar/qux/sidebar.html
/var/www/foo/bar/sidebar.html
/var/www/foo/sidebar.html
/var/www/sidebar.html