0
I am trying to show the date of the respective files that are inside a directory, however it is showing only the date of the last file in all the files... Any idea?
<?php
$path = "arquivos/";
// Título
echo "<h2>Lista de Arquivos:</h2><br />";
// Abre a tabela, cria títulos
echo "<table>";
echo "<tr> <th>Nome</th> ";
echo "<td> <th>Data</th> </td></tr>";
$data = date("d/m/Y H:i:s", filemtime("$path"));
// Loop que gera registros
foreach (new DirectoryIterator($path) as $fileInfo) {
if($fileInfo->isDot()) continue;
// Imprime linhas de registros
echo "<tr>
<td>
<a href='".$path.$fileInfo->getFilename() ."'>".$fileInfo->getFilename()."</a><br/>
</td>
<td>
".$data."
</td>
</tr>";
}
// Fecha a tabela
echo "</table>";
?>
Well, the variable
$data
is not changed within the repeat loop, so it is expected that the same value will be displayed. You should not update its value for each file?– Woss
The variable
$data
is only returning the folder date in$path
.– Sam