PHP as per the path and name of a file in variables

0

Hello. I have a table that should show the name of the files and the date they were updated, but nothing appears. In HTML I only have

<table><?php tabela("/arquivos/formularios/*.*"); ?></table> 

And in PHP:

function tabela($var){
    $globVar = glob($var);  

    for ($i=0; $i<count($globVar); $i++) {
        $caminho = $globVar[$i];
        if (file_exists($caminho)) {
            $nome = basename($caminho,".*");            
            echo "<tr><td class=\"td1\"><a href=\"".$caminho."\">".$nome."</a></td>
<td class=\"td2\">".date("d/m/Y", filemtime($caminho))."</td></tr>";
        }
    }   
}

When I load the page, I just see

<table></table>

Maybe I'm understanding glob () or another wrong function. Thank you if anyone can help me.

    
asked by anonymous 08.08.2014 / 20:38

3 answers

1

why not use scandir is much easier

example:

<?php

/*remove as pastas ".." e "." que podem aparecer em sistemas linux*/
$scan_dir = array_diff(scandir(__DIR__),array("..","."));

foreach ($scan_dir as $file_or_folder) {
    print $file_or_folder."<br/>";
}

? >

output

input.txt
main.php
folder1
folder2
    
08.08.2014 / 20:47
1

Function tabela() :

<?php

function tabela($var){
  error_reporting(E_ERROR | E_PARSE);
  $globVar = glob($var);
  $scan_dir = array_diff(scandir($var),array("..","."));
  echo "<table>";
  echo "<thead><th>Nome do Arquivo</th><th>Tamanho do Arquivo</th></thead>";
  foreach ($scan_dir as $file_or_folder) {
    print "<tr><td>".$file_or_folder."</td>";
    if (substr("$file_or_folder", 0, 1) != "."){
      print "<td>".date("d/m/Y", filemtime($file_or_folder))."</td></tr>";

    } else{
      print "</tr>";
    }
  }
  echo '</table>';
}
?>

Example Usage:

<?
tabela('./')
?>

Result:

Implemented suggestion of @William Borba, in the image instead of the size is the date, (detail that went unnoticed:))

    
08.08.2014 / 21:51
0

Take a look at this face:

link

This guy has everything you want is PHP native.

Recommendation: link

    
08.08.2014 / 22:58