-1

I wonder can anyone help me, I use this script as part of tinymce, and this displays the names of the graphics in the pics folder, but I want to show them alphabeticaly. Is this possible ?

Thanks in advance Eric

Script :

<?
echo 'var tinyMCEImageList = new Array(
';
$directory = "../pics";
if(is_dir($directory)){
$direc = opendir($directory);
$trenn = "";
while(false !== ($file = readdir($direc))){
    if($file !="." && $file != ".." ){
        if(is_file($directory."/".$file)){
            echo $trenn;
            $trenn = ",nt";
        echo '["'.$file.'", "../pics/'.$file.'"]';
        }
    }
}
closedir($direc);
}
echo ');'; 
?>
ericH
  • 1
  • 1
  • Have you tried searching StackOverflow and Google (etc) for things like "php alphabetical order", and "php order folders alphabetically"? I'm sure it must be such an easy solution, it will be just as easy to find ;) – James Oct 10 '14 at 16:21
  • Hi James, yeah I have tried googling etc but to no avail, I dont know if it is to be doen in javascript or php – ericH Oct 10 '14 at 16:25

1 Answers1

0

You can use glob, then natsort.

$arrFiles = glob("*"); //Fetch all files.
natsort( array_values($arrFiles) ); //Sort them using natural sort.
echo "<pre>";
echo print_r($arrFiles, true);
echo "</pre>";
ʰᵈˑ
  • 11,279
  • 3
  • 26
  • 49