how can I make recursive my index files manager

83 Views Asked by At

I'm making a file explorer with php but I have to put the file in each folder to be able to access it with my index. how can I make it dynamic or recursive and be able to enter with the same file index?

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>M07</title>
</head>
<body>

    <?php

        $contingut = "";

        if($handle = opendir('.')){
            while (false !== ($file = readdir($handle))){

                if (($file != ".") && ($file != "..") && ($file != "index.php") && ($file != "desktop.ini")){

                    $contingut .= '<a id="enllaç" href="'.$file.'">'.$file.'</a><br><br>';
                }
            }
            closedir($handle);
        }
?>
<?php echo $contingut ?>
1

There are 1 best solutions below

2
Ather Shahzad On
$di = new RecursiveDirectoryIterator('.');

foreach (new RecursiveIteratorIterator($di) as $filename => $file)
{

    if (($file != ".") && ($file != "..") 
    && ($file != "index.php") && ($file != "desktop.ini"))

    {           

        echo '<a id="enllaç" href="'.$file.'">'.$file.'</a><br>';

    }
}