Jump to content

Change Sort Order to Display Newest File First


Smedley

Recommended Posts

Hi Guys,

 

I have a page that sorts the contents (PDFs) of a directory and displays them on the webpage chronologically from the oldest (at top) to the newest (at bottom).

 

I'd like to reverse this display order and have the latest files display at the top with oldest at the bottom. The code is seen below:

 

Thanks in advance!!!  :D

 

<?php

$dir = opendir('../../files/main/group/info');

$i = 0;

// begin subdirectory processing

$subdir = "../../files/main/group/info"."/";

$cwd = opendir($subdir);

echo '<ul style="list-style: none;"><strong>';

while ($file = readdir($cwd)) {

if (($file != ".") && ($file != "..") && ($file != "README.txt")) {

$link = rawurlencode($file);

$tmp = basename($file, ".pdf");

$filename = date('F d, Y',strtotime($tmp));

echo '<li><img src="../../images/icons/pdf.gif" alt="PDF Document" /> <a href="' . $subdir, $link . '" target="_blank">' . $filename . '</a>';

}

}

echo "</strong></ul>";

?>

 

  • 2 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.