Bonjour,

je suis débutant en php, mon expérience avec le php à débuté ce matin et la FAQ et les tutos sont tellement riche que je n'ai sans doute pas tous vu alors je pose ma question pour m'orienter.
j'ai besoin d'une page qui affiche la liste des répertoires, en sélectionnant un répertoire, je veux afficher les fichiers disponible dans ce répertoire pour pouvoir les télécharger, il faut donc un lien sur chaque fichier pour le télécharger.
j'ai trouvé ce script sur Internet qui permet de faire exactement ce que je veux aprés quelques petites modifications sauf pour le lien de téléchargement :
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 
<html>
 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
 
<link rel="stylesheet" type="text/css" href="style.css">
</head>
 
<body>
<!--<table width="100%" border="1" ><tr><td>test</td></tr></table>-->
<?php
$order = isset($_GET['order']) ? $_GET['order'] : '';
$order0 = isset($_GET['order0']) ? $_GET['order0'] : '';
$dir = isset($_GET['dir']) ? $_GET['dir'] : '';
$asc = isset($_GET['asc']) ? $_GET['asc'] : '';
/* racine */
$BASE = '../';
/*$BASE = 'Documentation';*/
/* infos à extraire */
function addScheme($entry,$base,$type) {
  $tab['name'] = $entry;
  $tab['type'] = filetype($base.'/'.$entry);
  $tab['date'] = filemtime($base.'/'.$entry);
  $tab['size'] = filesize($base.'/'.$entry);
  $tab['perms'] = fileperms($base.'/'.$entry);
  $tab['access'] = fileatime($base.'/'.$entry);
  $t = explode('.', $entry);
  $tab['ext'] = $t[count($t)-1];
  return $tab;
}
/* liste des dossiers */
function list_dir($base, $cur, $level=0) {
  global $BASE, $order, $asc;
  if ($dir = opendir($base)) {
    $tab = array();
    while($entry = readdir($dir)) {
      if(is_dir($base.'/'.$entry) && !in_array($entry, array('.','..'))) {
        $tab[] = addScheme($entry, $base, 'dir');
      }
    }
    /* tri */
    usort($tab,'cmp_name');
    foreach($tab as $elem) {
      $entry = $elem['name'];
      /* chemin relatif à la racine */
      $file = $base.'/'.$entry;
     /* marge gauche */
      for($i=1; $i<=(4*$level); $i++) {
        echo ' ';
      }
      /* l'entrée est-elle le dossier courant */
      if($file == $cur) {
        echo "<img src=\"images/dir-open.gif\" /> $entry<br />\n";
      } else {
        echo "  <img src=\"images/dir-close.gif\" /> <a href=\"$_SERVER[PHP_SELF]?dir=".rawurlencode($file)."&order=$order&asc=$asc\">$entry</a><br />\n";
      }
      /* l'entrée est-elle dans la branche dont le dossier courant est la feuille */
      if(ereg($file.'/',$cur.'/')) {
        list_dir($file, $cur, $level+1);
      }
    }
    closedir($dir);
  }
}
/* liste des fichiers */
function list_file($cur) {
  global $order, $asc, $order0;
  if ($dir = opendir($cur)) {
    /* tableaux */
    $tab_dir = array();
    $tab_file = array();
    /* extraction */
    while($file = readdir($dir)) {
      if(is_dir($cur.'/'.$file)) {
        if(!in_array($file, array('.','..'))) {
          $tab_dir[] = addScheme($file, $cur, 'dir');
        }
      } else {
          $tab_file[] = addScheme($file, $cur, 'file');
      }
    }
    /* tri */
    usort($tab_dir,'cmp_'.$order);
    usort($tab_file,'cmp_'.$order);
    /* affichage */
    echo '<table cellspacing="0" cellpadding="0" border="1" width="100%">';
 echo '<tr style="font-size:8pt;font-family:arial;">
    <td>Nom</td>
    <td>Taille</td>
    <td>Dernière modification</td>
    <td>Type</td>
    <td>Extention</td>
    <td>Dernier accès</td></tr>';
    foreach($tab_file as $elem) {
      echo '<tr><td><img src="images/file-none.gif" /> '.$elem['name'].'</td>
      <td align="right">'.formatSize($elem['size']).'</td>
      <td>'.date("d/m/Y H:i:s", $elem['date']).'</td>
      <td>'.assocType($elem['type']).'</td>
      <td>'.assocExt($elem['ext']).'</td>
      <td>'.date("d/m/Y", $elem['access'])."</td></tr>\n";
    }
    echo "</table>";
    closedir($dir);
  }
}
/* formatage de la taille */
function formatSize($s) {
  /* unités */
  $u = array('octets','Ko','Mo','Go','To');
  /* compteur de passages dans la boucle */
  $i = 0;
  /* nombre à afficher */
  $m = 0;
  /* division par 1024 */
  while($s >= 1) {
    $m = $s;
    $s /= 1024;
    $i++;
  }
  if(!$i) $i=1;
  $d = explode('.',$m);
  /* s'il y a des décimales */
  if($d[0] != $m) {
    $m = number_format($m, 2, ',', ' ');
  }
  return $m.' '.$u[$i-1];
}
/* formatage du type */
function assocType($type) {
  /* tableau de conversion */
  $t = array(
    'fifo' => 'file',
    'char' => 'fichier spécial en mode caractère',
    'dir' => 'dossier',
    'block' => 'fichier spécial en mode bloc',
    'link' => 'lien symbolique',
    'file' => 'fichier',
    'unknown' => 'inconnu'
  );
  return $t[$type];
}
/* description de l'extention */
function assocExt($ext) {
  $e = array(
    '' => "inconnu",
    'doc' => "Microsoft Word",
    'xls' => "Microsoft Excel",
    'ppt' => "Microsoft Power Point",
    'pdf' => "Adobe Acrobat",
    'zip' => "Archive WinZip",
    'txt' => "Document texte",
    'gif' => "Image GIF",
    'jpg' => "Image JPEG",
    'png' => "Image PNG",
    'php' => "Script PHP",
    'php3' => "Script PHP",
    'htm' => "Page web",
    'html' => "Page web",
    'css' => "Feuille de style",
    'js' => "JavaScript"
  );
  if(in_array($ext, array_keys($e))) {
    return $e[$ext];
  } else {
    return $e[''];
  }
}
function cmp_name($a,$b) {
    global $asc;
    if ($a['name'] == $b['name']) return 0;
    if($asc == 'a') {
        return ($a['name'] < $b['name']) ? -1 : 1;
    } else {
        return ($a['name'] > $b['name']) ? -1 : 1;
    }
}
function cmp_size($a,$b) {
    global $asc;
    if ($a['size'] == $b['size']) return cmp_name($a,$b);
    if($asc == 'a') {
        return ($a['size'] < $b['size']) ? -1 : 1;
    } else {
        return ($a['size'] > $b['size']) ? -1 : 1;
    }
}
function cmp_date($a,$b) {
    global $asc;
    if ($a['date'] == $b['date']) return cmp_name($a,$b);
    if($asc == 'a') {
        return ($a['date'] < $b['date']) ? -1 : 1;
    } else {
        return ($a['date'] > $b['date']) ? -1 : 1;
    }
}
function cmp_access($a,$b) {
    global $asc;
    if ($a['access'] == $b['access']) return cmp_name($a,$b);
    if($asc == 'a') {
        return ($a['access'] < $b['access']) ? -1 : 1;
    } else {
        return ($a['access'] > $b['access']) ? -1 : 1;
    }
}
 
function cmp_type($a,$b) {
    global $asc;
    if ($a['type'] == $b['type']) return cmp_name($a,$b);
    if($asc == 'a') {
        return ($a['type'] < $b['type']) ? -1 : 1;
    } else {
        return ($a['type'] > $b['type']) ? -1 : 1;
    }
}
function cmp_ext($a,$b) {
    global $asc;
    if ($a['ext'] == $b['ext']) return cmp_name($a,$b);
    if($asc == 'a') {
        return ($a['ext'] < $b['ext']) ? -1 : 1;
    } else {
        return ($a['ext'] > $b['ext']) ? -1 : 1;
    }
}
?>
 
<table border="2" cellspacing="0" cellpadding="10" bordercolor="#0033CC" width="100%">
<tr>
	<td>liste des rep</td>
	<td>Nom</td>
</tr>
<tr valign="top"><td>
 
<!-- liste des répertoires
et des sous-répertoires -->
<?php
if(!in_array($order, array('name','date','size','perms','ext','access','type'))) {
  $order = 'name';
}
if(($order == $order0) && ($asc != 'b')) {
  $asc = 'b';
} else {
  $asc = 'a';
}
/* lien sur la racine */
if(!$dir) {
  echo "<img src=\"images/dir-open.gif\" /> /<br />\n";
} else {
  echo "<img src=\"images/dir-close.gif\" /> <a href=\"$_SERVER[PHP_SELF]\">/</a><br />\n";
}
list_dir($BASE, rawurldecode($dir), 1);  
?>
</td><td>
<!-- liste des fichiers -->
<?php
/* répertoire initial à lister */
if(!$dir) {
  $dir = $BASE;
}  
list_file(rawurldecode($dir));  
?>
</td></tr>
</table>
je pense qu'il faut voir du côté de la fonction cmp_name mais bon j'ose pas trop la toucher et je ne comprend pas comment je peux lui ajouter la balise de lien <a>

Merci pour votre aide.