如何在PHP中显示文件夹中任何文件的最新更改?我尝试过以下PHP / HTML代码,最终表行不起作用?有什么想法吗?
<?php
$lines = file("subjects.txt", FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$data = array_map(function($v){
list($username, $score) = explode(";", $v);
return ["subject" => $username];
}, $lines);
usort($data, function($a, $b){
if($a["subject"] == $b["subject"])
return 0;
return $a["subject"] > $b["subject"] ? 1 : -1;
});
?>
<!DOCTYPE html5>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
<title>Homework</title>
<link rel="icon" href="data:;base64,=">
</head>
<body>
<ul class="nav-bar">
<li>
<a class="blue" href="/homework/">Home</a>
</li>
<li>
<a href="/homework/subjects">Subjects</a>
</li>
<li>
<a href="/homework/list">All Homework</a>
</li>
<li>
<a href="../admin">Admin Login</a>
</li>
</ul>
<table>
<tr>
<th>Subject</th>
<th>Project</th>
<th>Last Edit</th>
</tr>
<?php foreach($data as $data){ ?>
<tr>
<td><?php echo $data["subject"]; ?></td>
<td><?php $dir = $data['subject'];$ffs = scandir($dir); foreach($ffs as $ff){ if($ff != '.' && $ff != '..'){ if(strpos($ff, '.')) {} else { $ff = ucfirst($ff); echo "<a href='../subjects/" . strtolower($ff) . "'>".$ff.'</a><br>'; } } } echo '</ol>'; }?></td>
<td><?php $path = "./" . $data["subject"]; echo date("F d Y", filemtime($path)); ?></td>
</tr>
</table>
<link rel="stylesheet" type="text/css" href="style.css" />
还有一个subjects.txt文件,其中包含一些主题,它显示正常,但最后一行除外。