begin process at 2012 05 27 20:08:57
  Trouver un code source :
 
dans
 
Accueil > 

Code

 > 

Divers

 > EXPLORATEUR DE REPERTOIRES EN PHP

EXPLORATEUR DE REPERTOIRES EN PHP


 Information sur la source

Note :
9 / 10 - par 1 personne
9,00 / 10

  • 1

  • 2

  • 3

  • 4

  • 5

  • 6

  • 7

  • 8

  • 9

  • 10
Catégorie :Divers Niveau :Débutant Date de création :01/03/2004 Date de mise à jour :01/03/2004 21:58:08 Vu :6 656

Auteur : hrz

Ecrire un message privé
Commentaire sur cette source (6)
Ajouter un commentaire et/ou une note

 Description

visualise le contenu des (sous)repertoires et les affiche dans une page html

Source

  • <HTML>
  • <!-- DATE DE CREATION: <?php print (date("r")); ?> -->
  • <HEAD>
  • <TITLE>Explorateur PHP</TITLE>
  • <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
  • </HEAD>
  • <BODY BGCOLOR=#ACD0D7 TEXT=#000000 LINK=#009900 VLINK=#FF6633 ONLOAD="prof.focus()">
  • <?php
  • function getmicrotime(){
  • list($usec, $sec) = explode(" ",microtime());
  • return ((float)$usec + (float)$sec);
  • }
  • $time_start = getmicrotime();
  • $prof=$_POST['prof'];
  • if (empty($prof)){$prof=1;}
  • ?>
  • <FORM ACTION="<?php print $_SERVER['SCRIPT_NAME']; ?>" METHOD=POST>
  • <P ALIGN="center">
  • <B>Profondeur d'exploration </B>
  • <INPUT TYPE="text" NAME="prof" SIZE=3 MAXLENGTH=3 VALUE="<?php print $prof; ?>"
  • ONCHANGE="window.location.submit(true)">&nbsp;
  • <INPUT TYPE="button" VALUE="Maxi" ONCLICK="prof.value='max';prof.focus();">
  • <HR SIZE=3 COLOR="#800000"></P>
  • <nobr>
  • <SCRIPT LANGUAGE="PHP">
  • // ******************************//
  • // Initialisation //
  • // ******************************//
  • //$prof="2"; // Profondeur d'exploration //
  • $TotalFichiers=0; // Total des fichiers trouver //
  • chdir("."); // Point de depart d'exploration //
  • // *************************** Initialiser la fonction
  • function Explore($Niv,$path,$prof){
  • global $prof,$TotalFichiers;
  • $TableRepertoires = array(); //******************************//
  • $TableFichiers= array(); // Variables locale //
  • $Entree= array(); //******************************//
  • $dir = opendir(".");
  • // *************************** lire les entrees
  • while ($File = readdir($dir)){
  • if($File != "." && $File != ".." ) {
  • $Entree[]= "$File";
  • }
  • $i++;
  • }
  • closedir($dir);
  • // *************************** Separer Repertoire / Fichiers
  • $Max = count($Entree);
  • for ($i = 0 ; $i != $Max ; $i++){
  • if (is_dir($Entree[$i])) {
  • $TableRepertoires[]="$Entree[$i]";
  • }else{
  • $TableFichiers[]= $Entree[$i];
  • }
  • }
  • // *************************** affiche le repertoire
  • sort ($TableRepertoires);
  • $Max = count($TableRepertoires);
  • for($i = 0; $i != $Max; $i++){
  • echo str_repeat("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|",$Niv-1);
  • //print "<B> <font color=\"#7F0000\">$Niv/$prof</font> <FONT COLOR=\"#FF0000\">&nbsp;$TableRepertoires[$i]</FONT></B> <BR>\n";
  • print "<font color=\"#7F0000\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+&nbsp;&nbsp;<b>$Niv/$prof</b></font><font size=\"+1\" color=\"#FF0000\">
  • <a href=\"$path$TableRepertoires[$i]/\"><b>$TableRepertoires[$i]</b></a></font><br />\n";
  • if ($Niv != $prof) { // si < maxi profondeur on y retourne
  • $Niv++;
  • $path_bak = $path;
  • chdir ("$TableRepertoires[$i]");
  • Explore($Niv,"$path$TableRepertoires[$i]/","");
  • chdir("..");
  • $path = $path_bak;
  • $Niv--;
  • }
  • }
  • // *************************** on affiche simplement les fichiers
  • sort ($TableFichiers);
  • $Max = count($TableFichiers);
  • for($i = 0; $i != $Max; $i++){
  • echo str_repeat("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|",$Niv);
  • //print "<FONT COLOR=\"#0000FF\"><B>&nbsp;&nbsp;$TableFichiers[$i]</B></FONT><BR>\n";
  • print "&nbsp;&nbsp;<a href=\"$path$TableFichiers[$i]\">$TableFichiers[$i]</a><br />\n";
  • }
  • $TotalFichiers += $Max;
  • echo str_repeat("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|",$Niv-1);
  • print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'-&raquo;";
  • print "<b><i>&nbsp;&nbsp;$Max</i> Fichiers </b><br>";
  • echo str_repeat("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|",$Niv-1);
  • print "<br>";
  • }
  • // *************************** fin des fonctions
  • $Table=Explore(1,"",$prof); // ******** on execute la fonction
  • $time_end = getmicrotime(); // temp final au retour
  • $time = $time_end - $time_start; // calcule le temp d'execution du script
  • print"<b><i><br>&nbsp;$TotalFichiers</i> Fichiers trouves</b> en: $time secondes<br>";
  • </SCRIPT>
  • </FORM>
  • </nobr>
  • </BODY>
  • </HTML>
<HTML>
<!-- DATE DE CREATION: <?php print (date("r")); ?> -->
<HEAD>
<TITLE>Explorateur PHP</TITLE>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
</HEAD>
<BODY BGCOLOR=#ACD0D7 TEXT=#000000 LINK=#009900 VLINK=#FF6633 ONLOAD="prof.focus()">

<?php 
function getmicrotime(){
    list($usec, $sec) = explode(" ",microtime());
    return ((float)$usec + (float)$sec);
  }
  $time_start = getmicrotime();
  
$prof=$_POST['prof'];
if (empty($prof)){$prof=1;}
?>
 <FORM ACTION="<?php print $_SERVER['SCRIPT_NAME'];  ?>" METHOD=POST>
<P ALIGN="center">
<B>Profondeur d'exploration </B>
<INPUT TYPE="text" NAME="prof" SIZE=3 MAXLENGTH=3 VALUE="<?php print $prof; ?>" 
  ONCHANGE="window.location.submit(true)">&nbsp;
<INPUT TYPE="button" VALUE="Maxi" ONCLICK="prof.value='max';prof.focus();">
<HR SIZE=3 COLOR="#800000"></P>
<nobr>
<SCRIPT LANGUAGE="PHP">

                                   // ******************************//
                                   //        Initialisation         //
                                   // ******************************//

//$prof="2";                          // Profondeur d'exploration      //
$TotalFichiers=0;                  // Total des fichiers trouver    //
chdir(".");                        // Point de depart d'exploration //

// ***************************           Initialiser la fonction
function Explore($Niv,$path,$prof){
    global $prof,$TotalFichiers;
    $TableRepertoires = array();   //******************************//
    $TableFichiers= array();       //      Variables locale        //
    $Entree= array();              //******************************//
    $dir = opendir(".");
// ***************************             lire les entrees
    while ($File = readdir($dir)){
        if($File != "." && $File != ".."  ) {
        $Entree[]= "$File";
        }
        $i++;
    }
    closedir($dir);
// ***************************              Separer Repertoire / Fichiers
    $Max = count($Entree);
    for ($i = 0 ; $i != $Max ; $i++){
        if (is_dir($Entree[$i])) {
           $TableRepertoires[]="$Entree[$i]";
        }else{
           $TableFichiers[]=  $Entree[$i];
        }
    }
// ***************************              affiche le repertoire
    sort ($TableRepertoires);
    $Max = count($TableRepertoires);
    for($i = 0; $i != $Max; $i++){
        echo str_repeat("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|",$Niv-1);
        //print "<B> <font color=\"#7F0000\">$Niv/$prof</font> <FONT COLOR=\"#FF0000\">&nbsp;$TableRepertoires[$i]</FONT></B> <BR>\n";
        print "<font color=\"#7F0000\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;+&nbsp;&nbsp;<b>$Niv/$prof</b></font><font size=\"+1\" color=\"#FF0000\">
                <a href=\"$path$TableRepertoires[$i]/\"><b>$TableRepertoires[$i]</b></a></font><br />\n";
        if ($Niv != $prof) {        // si < maxi profondeur on y retourne
		
           $Niv++;
           $path_bak = $path;
           chdir ("$TableRepertoires[$i]");
           Explore($Niv,"$path$TableRepertoires[$i]/","");
           chdir("..");
           $path = $path_bak;
           $Niv--;
        }
    }
// ***************************              on affiche simplement les fichiers
    sort ($TableFichiers);
    $Max = count($TableFichiers); 
    for($i = 0; $i != $Max; $i++){
        echo str_repeat("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|",$Niv);
        //print "<FONT COLOR=\"#0000FF\"><B>&nbsp;&nbsp;$TableFichiers[$i]</B></FONT><BR>\n";
        print "&nbsp;&nbsp;<a href=\"$path$TableFichiers[$i]\">$TableFichiers[$i]</a><br />\n";
    }
    $TotalFichiers += $Max;
    echo str_repeat("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|",$Niv-1);
	print "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'-&raquo;";
    print "<b><i>&nbsp;&nbsp;$Max</i> Fichiers </b><br>";
    echo str_repeat("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|",$Niv-1);
	print "<br>";
}
// ***************************             fin des fonctions


$Table=Explore(1,"",$prof); // ********          on execute la fonction
  $time_end = getmicrotime(); // temp final au retour
  $time = $time_end - $time_start; // calcule le temp d'execution du script
print"<b><i><br>&nbsp;$TotalFichiers</i> Fichiers  trouves</b> en: $time secondes<br>";

</SCRIPT>
</FORM>
</nobr>
</BODY>
</HTML> 

 Conclusion

- attention une trop grande profondeur d'exploration conduit a un timeout et les
  liens symbolique sont des boucles d'exploration possibles donc timeout aussi
- source commenter pour une adaptation possible
- copier le sur votre serveur ,le nom na pas d'importance
  en .php .php3 .php4 ......  il marche avec la directive RegisterGlobal = off
- respect les .htaccess (donne l'erreur et continu)

+++  un script tout cru pour ne pas se casser la tronche a le faire +++



 Sources du même auteur

Source avec Zip AVANCER OU REMONTER LE TEMP
ECRIVEZ SIMPLEMENT VOS BOITES LISTE DEROULANTE
Source avec Zip Source avec une capture CALENDRIER PHP

 Sources de la même categorie

Source avec une capture MODULE JOOMLA 1.5 NOW LISTENING par Alcantornet
Source avec Zip Source avec une capture UPLOAD CENTER par basssem81
Source avec Zip COMPTEUR DE CLIQUE PHP AVEC JQUERY par devgoneti
Source avec Zip LIVRE D'OR SIMPLE (POUR DÉBUTANT) par devgoneti
Source avec Zip SCRIPT TRAVAUX POUR VOTRE SITE par FleuryK

Commentaires et avis

Commentaire de iubito le 08/03/2004 06:42:54

erreur javascript et :

Notice: Undefined index: prof in F:\www\ex.php on line 16

Profondeur d'exploration [1   ] [maxi]
--------------------------------------------------------------------------------

Notice: Undefined variable: i in F:\www\ex.php on line 49      

ouais c'est bien beau le champ pour le niveau d'exploration, mais y'a rien pour valider et voir avec un autre niveau !?

Commentaire de hrz le 08/03/2004 20:13:06

la touche enter  peut etre ?
ou tu apelle la page avec en parametre la profondeur ?
ou une modification du debut de page ?

pour ma part le script est en ligne sur un site sans probleme ni en local

$prof=$_POST['prof'];// directive RegisterGlobal = off (PHP 4 )
si non ajouter // devant la ligne

pour erreur javascript : suprimer le onclick tout simplement

pour le retour du message d'erreur de la fonction ,il existe une solution simple dans le manuel php

Commentaire de hrz le 08/03/2004 20:13:24

la touche enter  peut etre ?
ou tu apelle la page avec en parametre la profondeur ?
ou une modification du debut de page ?

pour ma part le script est en ligne sur un site sans probleme ni en local

$prof=$_POST['prof'];// directive RegisterGlobal = off (PHP 4 )
si non ajouter // devant la ligne

pour erreur javascript : suprimer le onclick tout simplement

pour le retour du message d'erreur de la fonction ,il existe une solution simple dans le manuel php

Commentaire de babid le 11/03/2004 09:16:19

Salut,

Je ne vois pas l'utiliter mais l'idée est extra, le code bien détaillé et bien commenté, moi je dit chapeau 10/10
Mais petite erreur de javascript :
tu fais un onload dans le body appelant un champ du formulaire, or petit rappel un navigateur interprète ligne a ligne donc ton champ est indéfini au chargement de la page. Donc si tu veux éviter l'erreur rajoute le focus a la fin de ta page de code. Ainsi je descend a 9/10.

Bonne continuation

Commentaire de hrz le 13/03/2004 07:30:29

si j'ai bien compris  je remplace :
&lt;BODY BGCOLOR=#ACD0D7 TEXT=#000000 link=#009900 VLINK=#FF6633 ONLOAD="prof.focus()"&gt;

par
&lt;BODY BGCOLOR=#ACD0D7 TEXT=#000000 link=#009900 VLINK=#FF6633&gt;

et  &lt;/body&gt;
par &lt;/body  ONLOAD="prof.focus()"&gt;

? a voir !

Commentaire de babid le 15/03/2004 08:20:35

Salut,

HRZ, je ne pense pas qu'un onload fonctionne sur un /BODY, je te conseille plutot de mettre, avant la balise &lt;/BODY&gt; :

&lt;SCRIPT LANGAGE="javascript"&gt;
     document.forms[0].prof.focus();
&lt;/SCRIPT&gt;

Voila, bonne continuation

Bye

 Ajouter un commentaire




Nos sponsors


Sondage...

Comparez les prix

CalendriCode

Mai 2012
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Consulter la suite du CalendriCode

A découvrir



 
Développement réalisé par Nicolas SOREL (Nix) avec l'aide de : Cyril DURAND et Emmanuel (EBArtSoft), Merci à Vincent pour ses précieux conseils.
CodeS-SourceS.com© Toute reproduction même partielle est interdite sauf accord écrit du Webmaster
CodeS-SourceS.com© est une marque déposée tous droits réservés

Google Coop CodeS-SourceS Google Coop CodeS-SourceS
Temps d'éxécution de la page : 0,530 sec (3)

Nous contacter | Annoncer sur CodeS-SourceS | Mentions légales