mallen Posted December 17, 2009 Share Posted December 17, 2009 I have this code below that lists all files uploaded by users. The problem is they are in no order. I want to sort them by date. How can i do this? $x = 0; function parse_dir($dir) { if($dh = @opendir($dir)) { while(($file = readdir($dh)) !== false) { if($x == 0) { $color = "#CCCCCC"; } else { $color = "#EDECEC"; } if( !preg_match('/^\./s', $file) ) { if(is_dir($dir.$file)) { //nothing } else { echo '<tr> <td bgcolor='.$color.' class="style2"><a href="https://xxxxxx/'.$dir.$file.'">'.$dir.$file. ' '. date( 'm,j,y',filemtime("$dir$file")).'</a></td> <td width="20" bgcolor='.$color.' class="style2"> </td> <td width="80" bgcolor='.$color.' class="style2"><a href="delete.php?file='.$file.'">Delete</a></td> </tr>'; $x = $x + 1; if ($x == 2) { $x = 0; } } } } chdir('..'); } } parse_dir('upload/'); ?> Quote Link to comment https://forums.phpfreaks.com/topic/185483-sort-files-in-directory-by-date/ Share on other sites More sharing options...
salathe Posted December 17, 2009 Share Posted December 17, 2009 What PHP version are you using? There are some much easier, simpler, elegant (or all of the above) ways of doing this depending if your version allows it. Quote Link to comment https://forums.phpfreaks.com/topic/185483-sort-files-in-directory-by-date/#findComment-979348 Share on other sites More sharing options...
mallen Posted December 17, 2009 Author Share Posted December 17, 2009 I am using PHP 4.4.1 What PHP version are you using? There are some much easier, simpler, elegant (or all of the above) ways of doing this depending if your version allows it. Quote Link to comment https://forums.phpfreaks.com/topic/185483-sort-files-in-directory-by-date/#findComment-979372 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.