PHP: read all files but randomly?

Posted by mathiregister on Stack Overflow See other posts from Stack Overflow or by mathiregister
Published on 2010-06-02T07:18:54Z Indexed on 2010/06/02 7:23 UTC
Read the original article Hit count: 203

Filed under:
|

hi there, i wonder if there's a way of reading a directory in a random order.

With the following code i'm running through the directory thumbs and it's printing images on my website. However, they are always read alphabetically and i wonder if there's a way in doing this randomly?

<?php
$path = 'thumbs';
if ($handle = opendir($path)) {
    while (false !== ($file = readdir($handle))) {
        if ($file != '.' && $file != '..' && $file != '.DS_Store' && $file != 'Thumbs.db') {
                print "<img class='thumb' src='$path/$file'/>";

        } else {
            //no proper file
        }
    }
    closedir($handle);
}
?>

thank you for your suggestions!

regards

© Stack Overflow or respective owner

Related posts about php

Related posts about random