获取目录中的最后修改文件 [英] Get last modified file in a directory

查看:63
本文介绍了获取目录中的最后修改文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法只选择目录中的最后一个文件(扩展名为jpg|png|gif?)

Is there a way to select only the last file in a directory (with the extensions jpg|png|gif?)

还是我必须解析整个目录并使用filemtime检查?

Or do I have to parse the entire directory and check using filemtime?

推荐答案

是的,您必须通读它们.但是,由于目录访问已缓存,因此您不必担心.

Yes you have to read through them all. But since directory accesses are cached, you shouldn't really worry about it.

$files = array_merge(glob("img/*.png"), glob("img/*.jpg"));
$files = array_combine($files, array_map("filemtime", $files));
arsort($files);

$latest_file = key($files);

这篇关于获取目录中的最后修改文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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