0

I have this simple code that displays a list of files from a directory

<?php
$dir = opendir("pages");
while (($file = readdir($dir)) !== false)
{
if($file !="." AND $file !=".."){
echo "<a href=\"show_page.php?file=" .$file . "\">".$file."</a>";
echo "<br />";
}
}
closedir($dir);
?>

Can anyone please help edit this code to order the list displayed by date modified?

  • 5
    http://stackoverflow.com/questions/2667065/sort-files-by-date-in-php – tttony Jul 07 '16 at 15:59
  • I already checked it but the solutions listed didnt work for me, I have been trying them for hours. – Anas Waleed Jul 07 '16 at 16:02
  • 1
    Since you're opening a different directory than `.`, you need to prepend the directory name to the filename when you call `filemtime()`: `filemtime("$pages/$file")`. – Barmar Jul 07 '16 at 16:12
  • 1
    If you still can't get it to work, you need to show your code. Just saying "it didn't work for me" is not useful. – Barmar Jul 07 '16 at 16:13
  • I am not a PHP programmer, so starting from zero is probably much better than trying to edit my existing code (which is a mess), thats why I started a new question, to save a headache.. – Anas Waleed Jul 07 '16 at 16:38

0 Answers0