可能重复:
How to get X newest files from a directory in PHP?
Get most recent files recursively with PHP
我有一个脚本接收上传到www.bovicam / webcam的最新网络摄像头图像:
<?php
$dir = 'webcam/';
$base_url = 'http://www.bovicam.com/webcam/';
$newest_mtime = 0;
$show_file = 'BROKEN';
if ($handle = opendir($dir)) {
while (false !== ($file = readdir($handle))) {
if (($file != '.') && ($file != '..')) {
$mtime = filemtime("$dir/$file");
if ($mtime > $newest_mtime) {
$newest_mtime = $mtime;
$show_file = "$base_url/$file";
}
}
}
}
print '<img src="' .$show_file. '" alt="Current Bovicam webcam image - views across Bovisand Bay" style="width:90%; margin-top:7%; margin-bottom:3%;" class="displayed" id="webcam_image">';
?>
我想在网络摄像头下方的页面中显示最后六张图像。我没有能够按日期“标记”来自相机的文件,所以有没有办法通过“上次修改”来完成上述操作?