PHP readdir sorting problem, how to sort by date
高洛峰
高洛峰 2017-05-16 13:04:28
0
1
787

This is what it currently says:

function posts_get($directory,$ext)
{
    if (is_dir($directory)) {
    $handle = opendir($directory);
    while ($file = readdir($handle)){
    $subdir = $directory . '/' .$file;
    if ($file != '.' && $file !='..' && is_dir($subdir)){
    posts_get($subdir,$ext);
    } else if( $file != '.' && $file != '..') {
    $fileInfo = pathinfo($subdir);
    $fileExt = $fileInfo['extension'];
    if ($fileExt == $ext){
    echo 'File name:' . $file . '————' . 'Path:' . '//' .$_SERVER['HTTP_HOST'] . '/' .$directory . '/' . $file . ' <br />';
    }}}
    closedir($handle);
    }
}

Get the html files in the posts directory. There are 5 files in the test directory, 404.html, 405.html, 406.html, 407.html, 408.html

The output results are as follows:

File name:405.html————Path://hotbox.ryongyon.com/posts/405.html
File name: 406.html————Path://hotbox.ryongyon.com/posts/406.html
File name: 407.html————Path://hotbox.ryongyon.com/posts/407.html
File name: 408.html————Path://hotbox.ryongyon.com/posts/408.html
File name: 404.html————Path://hotbox.ryongyon.com/posts/404.html

How to sort readdir results according to the date of file creation

高洛峰
高洛峰

拥有18年软件开发和IT教学经验。曾任多家上市公司技术总监、架构师、项目经理、高级软件工程师等职务。 网络人气名人讲师,...

reply all(1)
仅有的幸福
  • filectimeGet file creation time and convert to timestamp

  • Define an empty array and store data in the format 时间戳=>文件名

  • ksort或者krsortSort array

  • done

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template