Solved

reverse chrological order

Posted on 2004-10-25
730 Views
Last Modified: 2012-05-05
Hey guys, I'm using the following script to pull images out of a folder and throw them onto a website to quickly.  This script works GREAT, but, is there a way to modify this so that it pulls the pics out in reverse chronological order, IE newest first then older:

if (isset($_GET['folder']) && in_array($_GET['folder'],$folders))
{
$path = "./images/gallery/$folder";
$dir_handle = @opendir($path) or die("Unable to open $path");
while (false !== ($file = readdir($dir_handle)))
      {
    if($file == ".")
    continue;
    if($file == "..")
    continue;
    if($file == "Thumbs.db")
    continue;
    echo "<img src=\"./$path/$file\" width=100 height=100><br />";
      echo "<a href=\"./$path/$file\">$file</a><br />";
      }
closedir($dir_handle);
}

0
Question by:SHSUFLIGHT
    2 Comments
     
    LVL 48

    Accepted Solution

    by:
    You need first to collect also the date-times vi filemtime and use array_multisort to sort that result.

    Try this (untested):

    $files = array();
    $times = array();
    while (false !== ($file = readdir($dir_handle)))
         {
        if($file == ".")
        continue;
        if($file == "..")
        continue;
        if($file == "Thumbs.db")
        continue;
        $files[] = "./$path/$file";
        $mtime[] = filemtime("./$path/$file");
    }
    array_multisort($files, SORT_NUMERIC, SORT_DESC, $mtime);

    foreach($files as $file) {
        echo "<img src=\"$file\" width=100 height=100><br />";
        echo "<a href=\"$file\">$file</a><br />";
    }
    0
     

    Author Comment

    by:SHSUFLIGHT
    Spiffy, worked like a charm!!!

    Thanks much
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
    This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
    Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    884 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now