我将有一个包含多个子目录的目录。 我希望能够从每个目录中获取最后一个上传/修改的flv,并能够创建可以输出的格式化列表。
我之前使用glob和foreach来创建文件夹项目列表,但不知道如何完成此操作,只需从多个子目录中返回一个文件。
任何帮助将不胜感激
谢谢!
答案 0 :(得分:1)
<?php
$result = array();
foreach (new DirectoryIterator('/path/to/dir') as $item) {
if (!$item->isDot() && $item->isDir()) {
$result[$item->getFilename()] = $m = null;
foreach (new DirectoryIterator($item->getPathname()) as $subItem) {
if ($subItem->isFile() && $m < $subItem->getMTime()) {
$result[$item->getFilename()] = $subItem->getFilename();
$m = $subItem->getMTime();
}
}
}
}
答案 1 :(得分:0)
您正在锁定filemtime