I'm trying to search for a file and return the path. Originally I thought I could find a simple example but I googled till I was gogled 8-0 without success, so I pieced together the following from another script. Yep, of coarse it doesn't work.
Where I echo "Inside Path:" the path is there and correct. However it doesn't get returned to the addPath function. Why???? Aaarrrrggghhhhhhhh.
Code: Select all
<?php
function addpath($docroot, $file_to_find){
echo $docroot . "<br/>";
$path = search($file_to_find, $docroot);
echo "AddPath: " . $path . "<br/>";;
}
function search($target, $dir){
if(is_dir($dir)){
$dir2 = opendir($dir);
while(false !== ($file = readdir($dir2))){
if($file !="." && $file != ".."){
if(is_file($dir."/".$file)){
if(preg_match("/$target/i", $file)){
echo "Inside Path: " . $dir . "<br/>";
return $dir;
}
}else if(is_dir($dir."/".$file)){
search($target,$dir."/".$file);
}
}
}
closedir($dir2);
}
}
?>Thanking you in anticipation,
blade