Last Updated: February 25, 2016
·
609
· beuretv

ftp or Mysql : sort files by date

I use it in a blog project : http://flamebaitpics.com
You can see my infinit scroll for li : https://coderwall.com/p/elea7q

  if ($handle = opendir('./yourdos')) {  
    while (false !== ($file = readdir($handle))) {  
        if ($file != "." && $file != "..") {  

            $array_chaine[] = array('nom' => $file,         'date'=>filemtime("./yourdos/$file"));
        }  //if
    } //while 
    closedir($handle);  


function cmp($a, $b)  
{  
    if ($a['date'] == $b['date']) return 0; 
    return ($a['date'] > $b['date']) ? -1 : 1; 
}  //cmp
usort($array_chaine, "cmp"); 

while (list($key, $value) = each($array_chaine)) { 

} //while

} //if