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

Multiple PHP errors when clicking a link..and..removing a ghost..
Hi - I have 2 problems with a new website - homeswapvacations.com, which I need help solving.

Preg_match with an array
is there an away to use preg_match with an array?

i want to check a string with an array to s

Multiple Options for a Single Page
For this example I want to use the Handlers option which is under Fed Admin and all the related codi

phpMailer not working ..........
HI,
I was playing with the phpMailer script and tried to send a smiple mail using their test scri

Help with parsing this html
Hi,
I've got some html i just need a couple of strings from.. argh, it's freaking me out. I've t

problem with sql querry in php script
Hello guys,

What I want to do is I want to read out a csv file and then but te conent ot the

cyrillic string conversion question
Hello,

First time here...

I would like to know if there is a way to convert a

frames get header location..
i have two frames, one top, one bottom. how do i do a form on the bottom frame that gives me the ur

foreach and array need help combining
Hi guys.

Here's the code

Code: array(
'tag' => 'code',<

How to add advertisment on top of videos
Hello,
I was told that i should find the answer for this problem in this forums.
I searched a

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