PHP递归地按修改日期对文件夹扫描进行排序 [英] PHP Recursively File Folder Scan Sorted by Modification Date

查看:150
本文介绍了PHP递归地按修改日期对文件夹扫描进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用此脚本查看所有子文件夹和子文件夹的文件

I'm using this script to see all subfolders and files of subfolders

   function readfolder($dir)
    {
        global $tfile,$tdir;$i=0;$j=0;$myfiles;
        $myfiles[][] = array();
        if (is_dir($dir)) {
            if ($dh = opendir($dir)) {
                while (($file=readdir($dh)) !== false) {
                    if (!is_dir($dir."\\".$file))
                    {
                        $tfile[$i]=$file;
                        $i++;
                        echo $dir."\\".$file." <b>File</b><br>";
                    }
                    else {
                        if (($file != ".") && ($file != "..")) {
                        $tdir[$j]=$file;
                        echo $dir."\\".$file." <b>Directory</b><br>";
                        readfolder($dir."\\".$file);
                        $j++;
                        }
                    }
                }
                closedir($dh);
            }
        }
    }

    readfolder(".");

有人可以告诉我如何使用filemtime函数(或其他任何函数),以便可以按修改日期对子目录和文件进行排序吗?

Can someone tell me how can I use filemtime function (or whatever) so that I can sort subflders and files by modification date?

推荐答案

看看SPL

Have a look at the SPL DirectoryIterator. It's cleaner than what you're currently doing and trivial to make it recursive. It also has a suitable mtime method.

这篇关于PHP递归地按修改日期对文件夹扫描进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆