qualcuno ha una funzione che data una cartella e una stringa ricerca la stringa nel nome dei files contenuti nella cartella stessa e sue sottocartelle, dando poi l'eventuale elenco dei files che contengono la stringa?
grazie
qualcuno ha una funzione che data una cartella e una stringa ricerca la stringa nel nome dei files contenuti nella cartella stessa e sue sottocartelle, dando poi l'eventuale elenco dei files che contengono la stringa?
grazie
io ho fatto così ma non riesco a far si che cerci anche nelle sottocartelle:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento senza titolo</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="index.php">
<div align="center">
<input type="text" name="find" />
<input type="submit" name="Submit" value="cerca" />
</div></form>
<?php
if(isset($_POST['find'])){
$find=$_POST['find'];
//vede se ci sono cartelle
$dir = "./files";
$d = dir($dir);
$tot=0;
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != ".." && $file != ".htaccess" && $file != ".htpasswd") {
$pos = strpos($file, $find);
if($pos===false){
}else{echo ($file."
");}
}
}
closedir($handle);
}
}
?>
</body>
</html>
ho risolto con una funzione autoricorsiva:
<?php
if(isset($_POST['find'])&& $_POST['find']!=""){
$find=$_POST['find'];
//vede se ci sono cartelle
$dir = "./files";
function trova($dir, &$find){
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$pos = strpos($file, $find);
if($pos===false){}else{echo $dir."/".$file."
";}
if (is_dir($dir."/".$file))
{
trova($dir."/".$file,$find);
}
}
}
closedir($handle);
}
}
trova($dir,$find);
}
?>
![]()