Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

reverse chrological order

Posted on 2004-10-25
2
Medium Priority
?
782 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
Comment
Question by:SHSUFLIGHT
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 48

Accepted Solution

by:
hernst42 earned 1200 total points
ID: 12401047
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
ID: 12402432
Spiffy, worked like a charm!!!

Thanks much
0

Featured Post

Ask an Anonymous Question!

Don't feel intimidated by what you don't know. Ask your question anonymously. It's easy! Learn more and upgrade.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
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 dynamically set the form action using jQuery.
Suggested Courses

609 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