【发布时间】:2016-07-11 20:53:13
【问题描述】:
我构建了一个 webapp 来检查文件夹(监视文件夹)的内容,
现在我正在尝试根据 <tr></tr> 元素的创建时间为它们着色,例如如果文件夹是在一分钟前创建的,则 tr 元素应该是黄色的等等......
代码如下:
<?php
$currentTimeFormat = date("d.m.Y H:i",$currentTime);
echo "current time " . $currentTimeFormat;
if (count($watchFolder) > 0) {
echo '<table class=\'table table-reponsive table-bordered\'>';
echo '<tbody>';
foreach ($watchFolder as $key => $value) {
$currentWatchPath = $watchFolderPath . $key;
if(strtotime($currentWatchPath) < strtotime('-1 minute')) {
$class = "redtest";
}
if(strtotime($currentWatchPath) < strtotime('-1 hour')) {
$class = "bluetest";
}
if(strtotime($currentWatchPath) < strtotime('-1 day')) { # Older than one day
$class = "greentest";
}
echo '<thead class=\'thead-inverse\'>
<tr>
<th scope=\'row\' class='.$class.'>'.$key.' | Last change '.date("d.m.Y H:i", filemtime($currentWatchPath)).'</th>
</tr>
</thead>';
foreach ($value as $key => $valueSub) {
$currentWatchPath2 = $currentWatchPath . '\\' . $key;
echo '<tr>
<td class=\'grey\'>
<span class="glyphicon glyphicon-arrow-right"></span> '.$key.' | Last change '.date("d.m.Y H:i", filemtime($currentWatchPath2)).'</td>
</tr>';
foreach ($valueSub as $content) {
$currentWatchPath3 = $currentWatchPath2 . '\\' . $content;
echo '<tr>
<td>
<span class="glyphicon glyphicon-arrow-right"></span> '.$content.' | Last change '.date("d.m.Y H:i", filemtime($currentWatchPath3)).'</td>
</tr>';
}
}
}
echo '</tbody>';
echo '</table>';
}
?>
$watchfolder 是一个数组,其中包含特定路径的所有文件夹。
我得到了监视文件夹(和子文件夹)及其时间,这是可行的。
但是根据每个文件夹的创建时间为 tr 元素着色不能正常工作,在我的情况下,即使我创建一个新文件夹,所有 tr 元素都是绿色的,它是绿色的,而它应该是红色的。
一些建议会很酷。
因此,如果您认为可以改进我的代码,欢迎您!
【问题讨论】:
标签: php html arrays time foreach