【发布时间】:2019-03-05 07:01:35
【问题描述】:
我正在寻求一些帮助来完成这项工作。
在根目录中,我有一个 index.php 文件(如下所示),我还有 3 个文件夹。图像被随机添加到这些文件夹中,我想做的是在表格的这 3 列中显示(排序)每个文件夹中的最新文件及其创建/修改日期,或者基本上是添加日期。
我添加了一个屏幕截图来显示我到目前为止所拥有的内容,通过拉取每个文件夹中的最新文件,这 3 列工作正常。但是,在每张图片下,它们似乎都有相同的修改日期,这是错误的。
谁能看出我哪里出错了?
<?php
date_default_timezone_set('Europe/London');
$dirname = "dir1";
$dirnameTwo = "dir2";
$dirnameThree = "dir3";
$cam1 = scandir($dirname, 1);
$cam2 = scandir($dirnameTwo, 1);
$cam3 = scandir($dirnameThree, 1);
?>
<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>
<head>
<meta http-equiv='refresh' content='10'>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<meta http-equiv='cache-control' content='max-age=0' />
<meta http-equiv='cache-control' content='no-cache' />
<meta http-equiv='expires' content='0' />
<meta http-equiv='expires' content='Tue, 01 Jan 1980 1:00:00 GMT' />
<meta http-equiv='pragma' content='no-cache' />
</head>
<html>
<body>
<style type="text/css">
.pi-title {
padding: 1rem;
}
</style>
<div class="container">
<div class="row">
<div class="pi-title">
<h3>Testing</h3>
</div>
<div class="table-container col-md-12">
<table class="table" border='1' cellpadding='5' cellspacing='0' bordercolor='#ccc'>
<thead class="thead-dark">
<tr>
<th scope="col">ID</th>
<th scope="col">1</th>
<th scope="col">2</th>
<th scope="col">3</th>
</tr>
</thead>
<tbody>
<tr></tr>
<tr>
<?php
error_reporting(E_ALL & ~E_NOTICE);
array_multisort(array_map('filemtime', ($files = glob("*.*", GLOB_BRACE))), SORT_DESC, $files);
$dirs = array($dirname, $dirnameTwo, $dirnameThree);
foreach ($files as $filename) {
for ($i = 1; $i <= 12; $i++) {
if (file_exists($filename)) {
echo "</tr>";
echo "<td><font face='Arial' size='6'>$i</font></td>";
echo "<td><img src='$dirs[0]/$cam1[$i]' height='180' width='220'><br>" . date("F d Y H:i", filemtime($filename));
echo "</td>";
echo "<td><img src='$dirs[1]/$cam2[$i]' height='180' width='220'><br>" . date("F d Y H:i", filemtime($filename));
echo "</td>";
echo "<td><img src='$dirs[2]/$cam3[$i]' height='180' width='220'><br>" . date("F d Y H:i", filemtime($filename));
echo "</td>";
}
if ($i === 12) break;
}
if ($i === 12) break;
}
?>
</tr>
</tbody>
</table>
</div>
</div>
</div>
【问题讨论】:
标签: php