I checked at php.net [**opendir()**](http://php.net/manual/en/function.opendir.php) but found no way to control the order of the files that opendir() gets.

I have a slideshow and I have problems controling the order of the images. I tried changing names and use `01.img`,`02.img`,...,`20.img` but no sucess.

My script:

```
<?php
$path2 = "./img/";
function createDir($path2 = './img'){   
    if ($handle = opendir($path2)){
        echo "<ul class=\"ad-thumb-list\">";
        while (false !== ($file = readdir($handle))){
            if (is_dir($path2.$file) && $file != '.' && $file !='..')
                printSubDir($file, $path2, $queue);
            else if ($file != '.' && $file !='..')
                $queue[] = $file;
        }
        printQueue($queue, $path2);
        echo "</ul>";
    }
}

function printQueue($queue, $path2){
    foreach ($queue as $file){
        printFile($file, $path2);
    } 
}

function printFile($file, $path2){
    if ($file=="thumbs.db") {echo "";}
    else{
        echo "<li><a href=\"".$path2.$file."\">";
        echo "<img src=\"".$path2.$file."\" class='thumbnail'></a></li>";
    }
}

/*function printSubDir($dir, $path2)
{
}*/

createDir($path2);
?>

```