- <?php
- /* ************************************************************************ */
- // function listingDir par Nans Stefanini
- // http://nans.stefanini.free.fr
- // Fonction récursive permettant de générer une arborescence de fichiers
- // avec filtres
- // $path : chemin du dossier à lister
- // $ext_interdites : tableau des extensions interdites
- // $dir_interdits : tableau des noms de dossiers interdits
- // $file_interdits : tableau des fichiers interdits
- // $profondeur : nombre de dossier à explorer par rapport à $path
- // $profdep = 0 : ne pas toucher, valeur de départ
- /* ************************************************************************ */
-
- function listingDir($path, $ext_interdites, $dir_interdits , $file_interdits, $profondeur=9999, $profdep=0 ) {
-
-
- if (is_dir($path)) {
- if (substr($path, -1, 1) !='/') {
- $path .= '/';
- echo $path.'<br>';
- }
- }
-
- echo 'profdep='.$profdep.'<br />';
- //on compte le nb de / au lancement
- if ($profdep == 0) {
- $profdep= substr_count($path, '/');
- }
-
- if (is_dir($path)) {
- //on definit le nom du dossier à afficher
- if (substr($path, -1, 1) =='/') { //si ça finit par un slash on le vire pr avoir le nom du dossier
- $dirnam = substr($path, 0,(strlen($path)-1)); //on vire le dernier shash
- } else {
- $dirnam = substr($path, 0,(strlen($path))); //on garde le nom du dossier comme ça
- $path.= '/'; //et on ajoute un slash a la fin du path pr avoir d chemins ok
- }
- $dirnam = strrchr($dirnam, "/"); // on recup le nom du dernier dossier
- $dirnam = str_replace (array('/'), array(''), $dirnam); // on vire le 1er shash
- //echo 'yo='.$dirnam ;
- //echo '<br />';
-
- if(!in_array($dirnam, $dir_interdits)) { //on verrifie que le dossier fait pas partie des interdits
-
- echo '<strong><a href="#" onclick="if (document.getElementById(\'level'.$profondeur.$dirnam.'\').style.display!=\'block\') {document.getElementById(\'level'.$profondeur.$dirnam.'\').style.display=\'block\';} else { document.getElementById(\'level'.$profondeur.$dirnam.'\').style.display=\'none\' }">- '.$dirnam.'</a></strong><br /><div id="level'.$profondeur.$dirnam.'" style=" margin-left: 15px; display: none;">'."\n";
- if ($dh = @opendir($path)) {
- while (($file = readdir($dh)) !== false) {
- if (($file != '.') && ($file != '..') && ($file != '...')) {
-
- if (is_dir($path . $file)) {
- if (substr_count($path . $file, '/')-$profdep < $profondeur) {
-
-
- listingDir(($path . $file . '/'), $ext_interdites, $dir_interdits, $file_interdits, $profondeur, $profdep);
-
-
- }
- } else {
- //on chope l'extension et le nom du fichier
- $tabfile = explode('.', $file);
- $nomfile = $tabfile[0];
- $extfi = $tabfile[1];
-
- if(!in_array($extfi, $ext_interdites) && !in_array($file, $file_interdits)) { //on verif les extensions & fichiers interdits
- echo '<a href="'.$path . $file.'">'. $file.'</a><br>'."\n";
- }
- }
- }
- }
- closedir($dh);
-
- echo '</div>'."\n";
- }
- }
- }elseif (is_file($path)) {
- echo $path.'<br>';
- }
-
-
- }
-
- //ex
- listingDir('./dossier/', array('txt', 'sql', 'fla'), array('css', 'admin'), array('config.php', 'config.inc.php', 'desabo.html', 'formulaire.html'), 1);
-
- ?>
<?php
/* ************************************************************************ */
// function listingDir par Nans Stefanini
// http://nans.stefanini.free.fr
// Fonction récursive permettant de générer une arborescence de fichiers
// avec filtres
// $path : chemin du dossier à lister
// $ext_interdites : tableau des extensions interdites
// $dir_interdits : tableau des noms de dossiers interdits
// $file_interdits : tableau des fichiers interdits
// $profondeur : nombre de dossier à explorer par rapport à $path
// $profdep = 0 : ne pas toucher, valeur de départ
/* ************************************************************************ */
function listingDir($path, $ext_interdites, $dir_interdits , $file_interdits, $profondeur=9999, $profdep=0 ) {
if (is_dir($path)) {
if (substr($path, -1, 1) !='/') {
$path .= '/';
echo $path.'<br>';
}
}
echo 'profdep='.$profdep.'<br />';
//on compte le nb de / au lancement
if ($profdep == 0) {
$profdep= substr_count($path, '/');
}
if (is_dir($path)) {
//on definit le nom du dossier à afficher
if (substr($path, -1, 1) =='/') { //si ça finit par un slash on le vire pr avoir le nom du dossier
$dirnam = substr($path, 0,(strlen($path)-1)); //on vire le dernier shash
} else {
$dirnam = substr($path, 0,(strlen($path))); //on garde le nom du dossier comme ça
$path.= '/'; //et on ajoute un slash a la fin du path pr avoir d chemins ok
}
$dirnam = strrchr($dirnam, "/"); // on recup le nom du dernier dossier
$dirnam = str_replace (array('/'), array(''), $dirnam); // on vire le 1er shash
//echo 'yo='.$dirnam ;
//echo '<br />';
if(!in_array($dirnam, $dir_interdits)) { //on verrifie que le dossier fait pas partie des interdits
echo '<strong><a href="#" onclick="if (document.getElementById(\'level'.$profondeur.$dirnam.'\').style.display!=\'block\') {document.getElementById(\'level'.$profondeur.$dirnam.'\').style.display=\'block\';} else { document.getElementById(\'level'.$profondeur.$dirnam.'\').style.display=\'none\' }">- '.$dirnam.'</a></strong><br /><div id="level'.$profondeur.$dirnam.'" style=" margin-left: 15px; display: none;">'."\n";
if ($dh = @opendir($path)) {
while (($file = readdir($dh)) !== false) {
if (($file != '.') && ($file != '..') && ($file != '...')) {
if (is_dir($path . $file)) {
if (substr_count($path . $file, '/')-$profdep < $profondeur) {
listingDir(($path . $file . '/'), $ext_interdites, $dir_interdits, $file_interdits, $profondeur, $profdep);
}
} else {
//on chope l'extension et le nom du fichier
$tabfile = explode('.', $file);
$nomfile = $tabfile[0];
$extfi = $tabfile[1];
if(!in_array($extfi, $ext_interdites) && !in_array($file, $file_interdits)) { //on verif les extensions & fichiers interdits
echo '<a href="'.$path . $file.'">'. $file.'</a><br>'."\n";
}
}
}
}
closedir($dh);
echo '</div>'."\n";
}
}
}elseif (is_file($path)) {
echo $path.'<br>';
}
}
//ex
listingDir('./dossier/', array('txt', 'sql', 'fla'), array('css', 'admin'), array('config.php', 'config.inc.php', 'desabo.html', 'formulaire.html'), 1);
?>