Change Sort Order to Display Newest File First


Posted on 16th Feb 2014 07:03 pm by admin

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!!!

<?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" />&nbsp;<a href="' . $subdir, $link . '" target="_blank">' . $filename . '</a>';
}
}
echo "</strong></ul>";
?>

No comments posted yet

Your Answer:

Login to answer
220 Like 34 Dislike
Previous forums Next forums
Other forums

Please help with SMTP Authenticated PHP Email Form
Hello, I'm creating a PHP email form, and for this particular server, I have to use SMTP Authenticat

Greek characters in php
Hi,

I'm making a script and I m using for first time greek characters.
I started to write

UDS 4.0 Datatype issue
UDS 4.0.322 -- connecting to NI Labview 9.0

When using connection method: Cache with live

Collecting AOL Search Terms
I am attempting to collect AOL search terms. I know the code is correct (it works for google, bing,

Expandable Post Code
Hi,

Hope you can help. Which currently I haven't upgraded to connect to a mysql server, so i

Taxonomy? Classification? Categorisation?
Not sure if there is a way around this classification problem
I have a supplier who produces

Date/Time and Checkbox
Hi Everyone,

I am trying to figure out how to insert the current date and tim

Extracting URL pointer within XML tag
Hi.

I'm trying to extract text between two quotation marks in XML. For example, I want to ex

PHP and XML image gallery variable issue
I'm trying to display the large image on the same page as the thumbnails, to do that I'm passing a v

PHP and Javascript
Hello Everyone,

I have a page that needs a javascript code to be written between PHP code but

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash