如何获取PHP中目录中最后X个文件?获取目录中最后X个文件
我使用此代码获取最后一个文件,但我如何获得最后X个文件?
我的代码:
$path = "/path/test/";
$latest_ctime = 0;
$latest_filename = '';
$d = dir($path);
while (false !== ($entry = $d->read())) {
$filepath = "{$path}/{$entry}";
// could do also other checks than just checking whether the entry is a file
if (is_file($filepath) && filectime($filepath) > $latest_ctime) {
$latest_ctime = filectime($filepath);
$latest_filename = $entry;
}
}
你最后一个“X”文件是什么意思? – Shank
获取最后10个文件例如 –
我更新了您的问题,使用* n *而不是* x *:感觉更像是一个整数。也做了一些小的文法修正。 – trincot