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).

Did you know?Explore Trending and Topic pages for more stories like this.
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

xml
<?php

echo "<h1>XML Articles</h1>";

$home

PHP5 - Verifying a secure mail is secure
I need to send an e-mail from a form to a external department and because it contains personal custo

Display data returned from Ajaxservices!!
I have a question about displaying results using ajax. I have part of the code below.
$.ajax({

PHP Redirecting
Hello everyone. Is there a way to redirect people to pages within a statement in PHP? Since there is

PHP error (line 38) my website
Hello everyone, I'm new on this
and I got a web site thats got a error not showing the photos on<

A little help in c#
i am doing a simple paint program using c# i want to draw with the mouse so i wrote the code of the

Save remote XML to local website folder
Hi, I hope you can help me out. I would like to be able to pull an XML file from another site and t

include
Hi I have this way of licensing my PHP application, and I want to know if you guys can answer some q

Using insert variable
need a way to inert variable data to mysql database

$acc = "212121212";
$nok =

PHP onsubmit in the form not going to the fuction.
I have a form through ‘onsubmit’ calling a function validation(). But not going to the

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