ugrás a tartalomhoz

PHP alkönyvtárakban keresés help

DarkRaptor · 2008. Feb. 16. (Szo), 17.21
Sziasztok!

írtam egy olyan szkriptet, ami fájlokban rákeres egy beírt kulcsszóra és a találatot kilistázza egymás alá. Működik is szépen a kód, csak az a gond, hogy ez alkönyvtárakban nem keres. Eddig jutottam:
  1. <?  
  2.   
  3. print "  
  4. <form action=".$_SERVER['PHP_SELF']." method='post'>  
  5. <input type='text' name='keresendo' value='' />  
  6. <input type='hidden' name='s' value='1' />  
  7. <input type='submit' value='Keres' />  
  8. </form>";  
  9.   
  10. if($_POST["s"]=="1"){  
  11.     
  12. $list=array();  
  13. $path = "dir1";  
  14. $dh = opendir($path);  
  15. while (($file = readdir($dh)) !== false) {  
  16.     if($file != "." && $file != "..") {  
  17.         $list[]=$file;  
  18.     }  
  19. }  
  20. closedir($dh);  
  21.   
  22.   
  23.   $key=$_POST["keresendo"];  
  24.   $found='';  
  25.   
  26.   for ($i=0;$i<count($list);$i++) {  
  27.     $file=file($path ."/". $list[$i]);  
  28.   
  29.     for ($j=0;$j<count($file);$j++)  
  30.       if (strpos($file[$j],$key)>-1) {  
  31.         $found[]=$list[$i];  
  32.         break;  
  33.       }  
  34.   }  
  35.   
  36.   for ($i=0;$i<count($found);$i++)  
  37.     
  38. print "<a href='dir1/$found[$i]'>$found[$i]</a><br />";  
  39.   
  40. }  
  41.     
  42. ?>  
hogyan kéne ezt átalakítani úgy, hogy alkönyvtárakban is keressen?

nyílván az utolsó sort, ahol az <a href='dir1/... van, azt is át kéne írni, csak mire?

utánaolvastam ennek több helyen is, nézegettem az m_walk_dir() és a call_user_func() függvényeket, most az is_dir() függvénnyel szenvedek, de nem akar sehogysem összejönni a dolog.

segítségeteket előre is köszönöm!
 
1

javítva

DarkRaptor · 2008. Feb. 16. (Szo), 18.51
továbbdolgoztam a kódot, most itt tartok, de még mindig nem jó:
  1. <?php  
  2.   
  3. Function listdir($start_dir='.') {  
  4.   
  5.   $files = array();  
  6.   if (is_dir($start_dir)) {  
  7.     $fh = opendir($start_dir);  
  8.     while (($file = readdir($fh)) !== false) {  
  9.   
  10.      if (strcmp($file, '.')==0 || strcmp($file, '..')==0) continue;  
  11.       $filepath = $start_dir . '/' . $file;  
  12.       if ( is_dir($filepath) )  
  13.         $files = array_merge($files, listdir($filepath));  
  14.       else  
  15.         array_push($files, $filepath);  
  16.     }  
  17.     closedir($fh);  
  18.   } else {  
  19.     $files = false;  
  20.   }  
  21.   
  22.   return $files;  
  23.   
  24. }  
  25.   
  26. print "  
  27. <form action=".$_SERVER['PHP_SELF']." method='post'>  
  28. <input type='text' name='keresendo' value='' />  
  29. <input type='hidden' name='s' value='1' />  
  30. <input type='submit' value='Keres' />  
  31. </form>";  
  32.   
  33. if($_POST["s"]=="1"){  
  34.   
  35.  $key=$_POST["keresendo"];  
  36.   $found='';  
  37.    
  38.   $files = listdir($start_dir);  
  39.   
  40.   for ($i=0;$i<count($files);$i++) {  
  41.     $file=file($start_dir ."/". $files[$i]);  
  42.   
  43.     for ($j=0;$j<count($file);$j++)  
  44.       if (strpos($file[$j],$key)>-1) {  
  45.         $found[]=$files[$i];  
  46.         break;  
  47.       }  
  48.   }  
  49.   
  50.   for ($i=0;$i<count($found);$i++)  
  51.    
  52.   
  53. print_r($found);  
  54.   
  55. }  
  56. ?>  
hol rontottam el?
2

hasonló

Drawain · 2008. Feb. 16. (Szo), 19.53
Ez talán segíthet - ha az is_file utáni részt módosítod berakhatod a fájlnév vizsgálatot és kigyűjtheted egy tömbbe a találatokat.
3

thx

DarkRaptor · 2008. Feb. 17. (V), 11.35
köszönöm a segítségedet, másképp sikerült megoldanom! :)