0

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++;
 }
}
skaffman
  • 398,947
  • 96
  • 818
  • 769

2 Answers2

2

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

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
  • 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 May 11 '10 at 17:23
2

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

Jeremy Kendall
  • 2,869
  • 17
  • 17