Get the latest file addition in a directory

后端 未结 6 2010
鱼传尺愫
鱼传尺愫 2020-11-27 04:29

How to get the latest file name, or the file path that is added into a directory?

6条回答
  •  [愿得一人]
    2020-11-27 05:23

    $dir = dirname(__FILE__).DIRECTORY_SEPARATOR;
    $lastMod = 0;
    $lastModFile = '';
    foreach (scandir($dir) as $entry) {
        if (is_file($dir.$entry) && filectime($dir.$entry) > $lastMod) {
            $lastMod = filectime($dir.$entry);
            $lastModFile = $entry;
        }
    }
    

提交回复
热议问题