Ejemplo n.º 1
0
function exploreDir($dirname, $keyword)
{
    $allowedExt = ".php.pdf.chm";
    $dh = opendir($dirname);
    while ($file = readdir($dh)) {
        if (is_dir("{$dirname}/{$file}")) {
            if ($file != '.' and $file != '..') {
                exploreDir("{$dirname}/{$file}", $keyword);
            }
        } else {
            if ($file == 'index.php') {
                $file = basename($dirname);
                if (ereg($keyword, $file)) {
                    echo '<a href="', $dirname, '">', $file, '</a><br>';
                }
            } else {
                if (ereg($keyword, $file)) {
                    $ext = pathinfo($file, PATHINFO_EXTENSION);
                    $ext = ".{$ext}";
                    if (ereg($ext, $allowedExt)) {
                        echo '<a href="', $dirname, '/', $file, '">', basename($file, $ext), '</a><br>';
                    }
                }
            }
        }
    }
    closedir($dh);
}
Ejemplo n.º 2
0
function exploreDir($path)
{
    $folder = opendir($path);
    while ($entree = readdir($folder)) {
        //on ignore les entrees
        //prevenir la boucle infinie
        //lorsque'on parcours un répertoire on a toujours ces 2 dossiers en premier
        if ($entree != "." && $entree != "..") {
            //on verifie s'il s'agit d'un répertoire
            if (is_dir($path . "/" . $entree)) {
                $sav_path = $path;
                //construction du path vers le nouveau dossier
                $path .= "/" . $entree;
                //echo "dossier = ", $path, "<br>";
                // on parcours le nouveau répertoire
                exploreDir($path);
                $path = $sav_path;
            } else {
                $lastIndexPoint = strrpos($entree, ".");
                $extension = substr($entree, $lastIndexPoint, strlen($entree));
                // fichier html
                if (strstr($extension, "htm") != FALSE) {
                    echo "chemin vers fichier :  ", $path, "/", $entree, "<br>";
                }
            }
        }
    }
}