<?php
function findFile($root, $path, $filename) {
  $findFileAux = function($cwd, $filename) use (&$findFileAux, $root) {
    $file = "{$cwd}/{$filename}";
    
    // we can't do a file_exists check on a paste, echo istead
    // if (file_exists($file)) return file_get_contents($file);
    echo $file, "\n";
    
    if ($cwd === $root) return false;
    return $findFileAux(dirname($cwd), $filename);
  };
  return $findFileAux("{$root}/{$path}", $filename);
}

findFile("/var/www", "foo/bar/qux", "sidebar.html");