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

BackButton Behaviour in AJAX
I have an ASPX Page AJAX Enabled!The page has a gridView and a DDL for filtering on it. The Gridview

Pro-rata Billing in Periodic Billing for Rental
Hi guys,

We have a situation, where a rental contract starts at the mid of the month say

Question about the upload of large files
Hi there,

I have a question about the upload of large files, like videos (files generally abo

Taking an HTML form and a PHP program and making it into one working file.
Hello,

So I would like to display everything INSIDE a specific directory. In other words, I

very easy question about SQL info
Hello,
I think that I have a very easy question.
I know how to create a form using php SQL and

HTML Viewer HIDE scrollbar
How can I disable scrollbars in a HTML Viewer control? I can't hide them. Even i have enough space b

PHP Cannot redeclare class
I have 6 files, and two of them do not seem to want to play well. I keep getting a "Cannot rede

Getting a variable to work in function params
I have this fuction which is inside a class:

Code: public static function generateEmbedCode($

Thought I has this figured out especially after all the help i received?
Cags, Salathe, Daniel helped me with this yesterday, but not sure i took it all in.
I am attempti

need help in php variable
i have a php variable on one page
Code: [Select]$lastId = mysql_insert_id($db);
echo $lastId;<

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