Visualizzazione dei risultati da 1 a 3 su 3

Discussione: cerca nel file system

  1. #1

    cerca nel file system

    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

  2. #2
    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>

  3. #3
    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);

    }
    ?>


Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.