Page 1 of 1

[php] loading images in back order (from Z to A)

Posted: Mon May 04, 2009 7:04 am
by zolder
This code loading all images from folder 'test' but in name order - 'form A to Z'. I want to load images invertly - 'from Z to A'. Do You have any ideas?

Code: Select all

<?php
    if ($handle = opendir('test'))
        {
        while (false !== ($file = readdir($handle)))
            {
            if ($file != "." && $file != ".." && $file != "index.html")
                {
                echo "<img src=test/$file></a>";
                }
            }
        closedir($handle);
        }
?>

Re: [php] loading images in back order (from Z to A)

Posted: Mon May 04, 2009 9:56 am
by pickle
In your loop, rather than outputing the image, put it in an array. Call rsort() on that array. Loop through that array & output the images in (now) reverse order.

Re: [php] loading images in back order (from Z to A)

Posted: Mon May 04, 2009 3:27 pm
by McInfo
Also:

PHP Manual: scandir()
array scandir ( string $directory [, int $sorting_order [, resource $context]] )
PHP Manual: is_file()

Edit: This post was recovered from search engine cache.