Membres


Pas encore membre ?
inscrivez-vous ici

Connexion :
Login
Code
Mot de passe perdu ?
Liste des membres

Lecture récursive d'un répertoire - Fichiers / Répertoires

Lecture récursive d'un répertoire

Lecture récursive d'un répertoire


Lecture récursive d'un répertoire en PHP en décalant chaque niveau de répertoire de 3 espaces.
Pas du haut vol comme programmation, mais, ça fonctionne pas mal. Adaptable avec un peut de connaissance à beaucoup de projet.

Une demo est visible ici : Lecture récursive

<?php
function liste($dir){
if(
$_GET[v]){ $v=$_GET[v]; }

$dossier=opendir($dir);
while(
$fichier=readdir($dossier)){
$berk=array('.''..');
if(!
in_array($fichier,$berk)){

$lien="$dir/$fichier";
$nbrT=count(split("/",$lien))-2;
if(
$v==$lien){ $here='<span class="here">';$hereEnd='</span>'; } else{ $here='<span class="hereOn">';$hereEnd='</span>'; }
$space="";
for(
$i=1$i<$nbrT$i++){ $space.='&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'; }

if(
is_dir($dir."/".$fichier)){
echo 
$space.'<img src="/tutoriel/rep.jpg" border="0"> '.$here.'<b> <a href="index.php?v='.$lien.'">'.ucfirst($fichier).'</a> </b>'.$hereEnd.'<br />';
liste("$dir/$fichier");
}

}
}
}

function 
listeFichier($dir){
if(
$_GET[v]){ $v=$_GET[v]; }

$dossier=opendir($dir);
while(
$fichier=readdir($dossier)){
$berk=array('.''..');
if(!
in_array($fichier,$berk)){

$lien="$dir/$fichier";

if(!
is_dir($dir."/".$fichier)){
echo 
' '.ucfirst($fichier).' <br />';
}

}
}
}

$v=htmlentities($_GET[v]);
$situation=str_replace("./test/","",$v); $situation=str_replace("/"," > ",$situation);

echo 
'<table width="100%"><tr valign="top"><td width="200">';
liste("./test");
echo 
'</td><td>
<b>Les fichiers</b> ['
.$situation.']<br /><br />';
if(
$v){ listeFichier($v); }else{ echo 'Cliquez sur un répertoire'; }
echo 
'</td></tr></table>';
?>


Les CSS utilisé :
<style type="text/css">
.here a {
font-weight: bold;
color: red;
text-decoration: none;
font-variant: small-caps;
}
.here a:hover {
font-weight: bold;
color: darkblue;
text-decoration: none;
font-variant: small-caps;
}

.hereOn a {
font-weight: bold;
text-decoration: none;
color: #2B53A8;
font-variant: small-caps;
}
.hereOn a:hover {
font-weight: bold;
color: #E63E00;
text-decoration: none
font-variant: small-caps;
}
</style>

Ecrit le 3-/-0/2005 par Sky
http://www.graphiks.net/


Ajouter un commentaire
  • Le 22-01-2008, yanis a écrit :
    c&#039;est bien de savoire qu&#039;il ya des gens qui travail tous mes encouragements
  •  

Pseudo :
Texte :

Nous  -  Plan du site  -  Informations légale  -  Contact  -  © Graphiks.net