views:

130

answers:

2

Hello,

I'm having problems with a PHP script trying to list images alphabetically. I need this urgently and I have not much knowledge of PHP. I was trying to use scandir() but I'm not succeeding. Thanks for your help!!

Here is the code:

function listerImages($repertoire){

 $i = 0;
 $repertoireCourant = opendir('./'.$repertoire);
 while($fichierTrouve = readdir($repertoireCourant)){

  $fichierTemp = "";

  if($repertoire == '.')
   $fichierTemp = $fichierTrouve;
  else 
   $fichierTemp = $repertoire.'/'.$fichierTrouve;
  if(estUneImageValide($fichierTemp)){
   echo afficherPhoto($fichierTemp,$i);
   chmod($fichierTemp,0700);
  }

  $i++;
 }
}
+2  A: 

Store the entries in an array so that you can sort them before outputting.

Ignacio Vazquez-Abrams
readdir() and company return files in the order in which they're stored in the directory entry, which is the order in which they were added to the directory to begin with
Marc B
+2  A: 

I agree with Ignacio. See the Sorting Arrays section of the PHP manual.

Jeremy Kendall