List data files using PHP-mysql

Asked

Viewed 252 times

-1

Hello. I am a beginner in programming and I am developing a project. I have already performed the code to upload the file, now I would like to list these files in a table and it shows a column with the name file and another column with the date attached (according to the time in the database):

<body>
    <h3>Arquivos Adicionados:</h3>
    <?php
        $path = "upload/";
        $diretorio = dir($path);

        echo "<div class='table-responsive'>";
        echo "<table class='table'>";
        echo "<thead class='thead-dark'>";
        echo "<tr>";
        echo "<th>Nome</th>";
        echo "<th>Data/Hora</th>";
        echo "</tr>";
        echo "</thead>";

        while($arquivo = $diretorio -> read()){
            echo "<tbody>"; 
            echo "<tr>";
            echo "<td><a href='".$path.$arquivo."' style='text-decoration:none'>".$arquivo."</a></td>";
            echo "<td>" ??? "</td>";                
            echo "</tr>";
            echo "</tbody>"; 
        }
        echo "</table><br>";

    $diretorio -> close();
    ?>
    <a href="add_arquivos.php"><button class="btn btn-primary">Inserir +</button></a>
</body>

1 answer

0

Using filesystem DATA, that is the date the server created the file in this method is not possible since the dir() function returns only the filenames. You’d have to do:

echo "<td>";
        echo date ("F d Y H:i:s.", filemtime($arquivo));
        echo "</td>";

in place of:

echo "<td>" ??? "</td>";
  • Thank you very much, Romeo. I added $path to the code and it looked like this: echo "<td>". date ("d/m/Y", filemtime($path.$file))." </td>"; Because I was returning the date January 01 1970. But now I gave it right. Thanks anyway

  • Yes, well remembered, I had forgotten to add the path to the files.... Then it always returns 0 because the file may be non-existent.....

Browser other questions tagged

You are not signed in. Login or sign up in order to post.