user338233
user338233

Reputation: 1

PHP (images folder) image Listing in Alphabetical Order?

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++;
 }
}

Upvotes: 0

Views: 621

Answers (2)

Jeremy Kendall
Jeremy Kendall

Reputation: 2869

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

Upvotes: 2

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798566

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

Upvotes: 2

Related Questions