Ti propongo questo.
Devi settare due costanti
SITE_PATH_START che è l'url della cartella di partenza della ricerca
SITE_FILE_SYSTEM_START che è il path della cartella di partenza della ricerca
Le costanti ti consento di limitare la ricerca alle cartelle che desideri.
Entrambi devono puntare sullo stesso posto come nell'esempio qui sotto.
codice:
<?
define ("SITE_PATH_START","http://localhost/site2");
define ("SITE_FILE_SYSTEM_START","C:/Program Files/EasyPHP/www/Site2");
function cercaFile($nomeFile,$from) {
$open= @OpenDir($from);
while($currentEntry=@ReadDir($open)) {
if(($currentEntry!=".")&&($currentEntry!="..")) {
$nextSubDir = $from."/".$currentEntry;
$repname = $currentEntry;
if (is_dir($nextSubDir )) {
$found = cercaFile($nomeFile,$nextSubDir);
if ($found) {
return $found;
} // if ($found)
} // if (is_dir($nextSubDir ))
if ($currentEntry == $nomeFile) {
$file = str_replace(SITE_FILE_SYSTEM_START,SITE_PATH_START,$nextSubDir);
return $file;
} // if ($currentEntry == $nomeFile)
} // if(($currentEntry!=".")&&($currentEntry!=".."))
} // while($currentEntry=@ReadDir($open))
return false;
} // function cercaFile($nomeFile,$from)
$found = cercaFile("doc_xxx.php",SITE_FILE_SYSTEM_START);
if ($found) {
print "trovato $found";
} else {
print "non trovato";
}
?>
La funzione ritorna l'url del file o false se non trovato.