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

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zolder
Forum Newbie
Posts: 1
Joined: Mon May 04, 2009 6:57 am

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

Post 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);
        }
?>
Last edited by Benjamin on Mon May 04, 2009 8:52 am, edited 1 time in total.
Reason: Changed code type from text to php.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

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

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

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

Post 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.
Post Reply