ccc

Recorrer y mostrar todos los ficheros de una carpeta

function showFiles($path){
    $dir = opendir($path);
    $files = array();
    while ($current = readdir($dir)){
        if( $current != "." && $current != "..") {
            if(is_dir($path.$current)) {
                showFiles($path.$current.'/');
            }
            else {
                $files[] = $current;
            }
        }
    }
    echo '<h2>'.$path.'</h2>';
    echo '<ul>';
    for($i=0; $i<count( $files ); $i++){
        echo '<li>'.$files[$i]."</li>";
    }
    echo '</ul>';
}

showFiles('./');

No hay comentarios:

Publicar un comentario