login  Naam:   Wachtwoord: 
Registreer je!
 Scripts:

Scripts > PHP > Overige scripts > Bestanden doorzoeken

Bestanden doorzoeken

Auteur: Stijn1 - 25 september 2004 - 21:23 - Gekeurd door: Dennisvb - Hits: 5299 - Aantal punten: (0 stemmen)




Dit is een klein scriptje dat je map doorleest (ook submaps) en zoekt naar bestanden. Dan kan je uit die bestanden kiezen in welk je wilt zoeken...
Gebruik:
  1. <?php
  2. echo zoek(dir_array('..', array('txt', 'html'))); // die .. is de map die array is de toegelate extenties. Plaats hier nooit php bestanden, dan kan je de source bekijken...
  3. ?>


Code:
  1. <?php
  2. function dir_array($map, $wt){
  3. if($bestand = opendir($map)){
  4. while(false !== ($lees = readdir($bestand))){
  5. if($lees != "." && $lees != ".."){
  6. $ex = explode('.', $lees);
  7. $ext = $ex[count($ex)-1];
  8. if(is_dir($map."/".$lees)){
  9. $da = array_merge($da, dir_array($map."/".$lees, $wt));
  10. }
  11. elseif(in_array($ext, $wt)){
  12. $da[] = $map."/".$lees;
  13. }
  14. }
  15. }
  16. closedir($bestand);
  17. }
  18. return $da;
  19. }
  20. function zoek($array){
  21. if($array <= 0){
  22. $sel = '<input type="text" name="bestand" value="'.$_POST["bestand"].'">';
  23. }
  24. else{
  25. echo $map;
  26. $sel = " <select name=\"bestand\">";
  27. foreach($array as $dir){
  28. $sel .= "\n <option>".$dir."</option>";
  29. }
  30. $sel .= "\n </select>";
  31. }
  32. $form = '<form name="zoek_form" method="post">
  33. <table width="100%" border="0" cellspacing="0" cellpadding="3">
  34. <tr>
  35. <td><strong>Woord:</strong></td>
  36. <td><input type="text" name="woord" value="'.$_POST["woord"].'"></td>
  37. </tr>
  38. <tr>
  39. <td><strong>Bestand:</strong></td>
  40. <td>
  41. '.$sel.'
  42. </td>
  43. </tr>
  44. <tr>
  45. <td>&nbsp;</td>
  46. <td><input type="submit" name="zoek" value="Zoek"></td>
  47. </tr>
  48. </table>
  49. </form>';
  50. if($_POST["bestand"] != '' && $_POST["woord"] != ''){
  51. if(file_exists($_POST["bestand"])){
  52. $bestand = file($_POST["bestand"]);
  53. $bestand = implode("<br />", $bestand);
  54. $bestand = preg_replace('/'.$_POST["woord"].'/i', '<font style="background: yellow">'.$_POST["woord"].'</font>', $bestand);
  55. return $form.'<hr size="1" color="black" />'.$bestand;
  56. }
  57. else{
  58. return $form.'<hr size="1" color="black" />Dit bestand bestaat niet!';
  59. }
  60. }
  61. else{
  62. return $form;
  63. }
  64. }
  65. ?>
Download code! Download code (.txt)

 Stemmen
Niet ingelogd.

 Reacties
Post een reactie
Geen reacties (0)
© 2002-2024 Sitemasters.be - Regels - Laadtijd: 0.034s