<?php
// ------------------------------------------------------------------------- //
// Auteur: Jérémy                                                            //
// Email:  jeremy.lecour@wanadoo.fr                                          //
// Web:    http://desperaweb.com/                                            //
// ------------------------------------------------------------------------- //
// Ce script permet de lister toute l'arborescence d'un dossier              //
// récursivement. Je me suis inspiré de plusieurs scripts faisant des        //
// copies / destructions récursives.                                         //
// La fonction principale est list_dir($path,$step) où $path est le chemin   //
// d'access du répetoire à lister et $step doit être égal à 1 pour commencer //
// (ça sert à l'indentation).                                                //
// La fonction indent($step) permet d'indenter les fichier pour clarifier    //
// l'arborescence.                                                           //
// La fonction extension($file) sert à afficher une icone avant le nom des   //
// dossiers/fichiers. Cette fonction peut-être simplifiée si on ne veut pas  //
// afficher toutes ces icones                                                //
// ------------------------------------------------------------------------- //
function extension($file)
{
        
    
$ext = strrchr ( $file , "." );
    
############### Folder
    
if ( $file == "folder" )
    {
        
$icon  = "<IMG SRC='folder.gif' alt='Dossier' border='0' width='15' ";
        
$icon .= "height='13' hspace='3' vspace='3'>";
        
############### Image
    
}
    else if ((!
strcasecmp ($ext, ".gif")) || (!strcasecmp ($ext, ".jpg")) ||
             (!
strcasecmp ($ext, ".png")) || (!strcasecmp ($ext, ".bmp")) ||
             (!
strcasecmp ($ext, ".jpeg")))
    {
        
$icon = "<IMG SRC='image.gif' alt='Image' border='0' width='16' ";
        
$icon .= "height='16' hspace='3' vspace='2'>";
        
############### Textfile
    
}
    else if (!
strcasecmp ($ext, ".txt"))
    {
        
$icon = "<IMG SRC='text.gif' alt='Text' border='0' width='16' ";
        
$icon .= "height='16' hspace='3' vspace='2'>";
        
############### Audiofile
    
}
    else if ((!
strcasecmp ($ext, ".wav")) || (!strcasecmp ($ext, ".mp2")) ||
             (!
strcasecmp ($ext, ".mp3")) || (!strcasecmp ($ext, ".mp4")) ||
             (!
strcasecmp ($ext, ".vqf")) || (!strcasecmp ($ext, ".midi")) ||
             (!
strcasecmp ($ext, ".mid")))
    {
        
$icon = "<IMG SRC='audio.gif' alt='Audio' border='0' width='16' ";
        
$icon .= "height='16' hspace='3' vspace='2'>";
        
############### Webscript
    
}
    else if ((!
strcasecmp ($ext, ".phps")) || (!strcasecmp ($ext, ".php")) ||
             (!
strcasecmp ($ext, ".php2")) || (!strcasecmp ($ext, ".php3")) ||
             (!
strcasecmp ($ext, ".php4")) || (!strcasecmp ($ext, ".phtml")) ||
             (!
strcasecmp ($ext, ".asp")) || (!strcasecmp ($ext, ".asa")) ||
             (!
strcasecmp ($ext, ".cgi")) || (!strcasecmp ($ext, ".shtml")) ||
             (!
strcasecmp ($ext, ".pl")))
    {
        
$icon = "<IMG SRC='webscript.gif' alt='Web program' border='0' ";
        
$icon .= "width='15' height='15' hspace='3' vspace='2'>";
        
############### Apache Webserver security settings
    
}
    else if (!
strcasecmp ($ext, ".htaccess"))
    {
        
$icon = "<IMG SRC='security.gif' alt='Apache Webserver security ";
        
$icon .= "settings' border='0' width='15' height='16' hspace='3' vspace='2'>";
        
############### Web page
    
}
    else if ((!
strcasecmp ($ext, ".html")) || (!strcasecmp ($ext, ".htm")))
    {
        
$icon = "<IMG SRC='webpage.gif' alt='Web page' border='0' width='15' ";
        
$icon .= "height='15' hspace='3' vspace='2'>";
        
############### WAP page
    
}
    else if (!
strcasecmp ($ext, ".wml"))
    {
        
$icon = "<IMG SRC='webscript.gif' alt='WAP page' border='0' ";
        
$icon .= "width='15' height='15' hspace='3' vspace='2'>";
        
############### Compressed file
    
}
    else if ((!
strcasecmp ($ext, ".zip")) || (!strcasecmp ($ext, ".tar")) ||
             (!
strcasecmp ($ext, ".rar")) || (!strcasecmp ($ext, ".gz")))
    {
        
$icon = "<IMG SRC='text.gif' alt='Compressed file' border='0' ";
        
$icon .= "width='15' height='15' hspace='3' vspace='2'>";
        
############### PowerPoint file
    
}
    else if ((!
strcasecmp ($ext, ".ppt")) || (!strcasecmp ($ext, ".pps")))
    {
        
$icon = "<IMG SRC='powerpoint.gif' alt='PowerPoint file' border='0' ";
        
$icon .= "width='16' height='16' hspace='3' vspace='2'>";
        
############### PDF file
    
}
    else if ((!
strcasecmp ($ext, ".pdf")))
    {
        
$icon = "<IMG SRC='pdf.gif' alt='PDF file' border='0' width='16' ";
        
$icon .= "height='16' hspace='3' vspace='2'>";
        
############### Word file
    
}
    else if ((!
strcasecmp ($ext, ".doc")))
    {
        
$icon = "<IMG SRC='doc.gif' alt='Word file' border='0' width='16' ";
        
$icon .= "height='16' hspace='3' vspace='2'>";
        
############### Excel file
    
}
    else if ((!
strcasecmp ($ext, ".xls")) || (!strcasecmp ($ext, ".xl")) ||
             (!
strcasecmp ($ext, ".tab")))
    {
        
$icon = "<IMG SRC='xls.gif' alt='Excel file' border='0' width='16' ";
        
$icon .= "height='16' hspace='3' vspace='2'>";
        
############### Unknown
    
}
    else
    {
        
$icon = "<IMG SRC='text.gif' alt='Unknown filetype' border='0' ";
        
$icon .= "width='16' height='16' hspace='3' vspace='2'>";
    }
    
    return
$icon;
}

function
indent($max)
{
    for (
$i=1;$i<$max;$i++)
        echo
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
}

function
list_dir ($path,$step)
{
    if (
$dir = @opendir($path))
    {
        while(
$file = readdir($dir))
        {
            if (
$file !="." && $file != "..")
            {
                if (
is_dir($path."/".$file))
                {
                    
indent($step);
                    echo
extension("folder")."<font size='-1'>$file</font>\n<br>";
                    
list_dir ($path."/".$file, $step+1);
                }
                else
                {
                    
indent($step);
                    echo
extension($file)."<font size='-1'>$file</font>\n<br>";
                }
            }
        }
        
        
closedir($dir);
    }
    else
        echo
"<b>ERREUR : $path</b> n'est pas un dossier !!\n<br>";
}

?>