Written by Sean Behan on Sun Jun 17th 2012

Listing all files and directories using PHP 5.

<?php
$files = array(); $dir = dir(".");
while(false!==($file=$dir->read())):
  if(($file{0}!=".") && ($file{0}!="~") && (substr($file, -3)!="LCK")
    && ($file!=basename($_SERVER["PHP_SELF"]))):
      $files[$file] = stat($file); //
    endif;
endwhile;
$dir->close(); ksort($files); ?>

<table border=1 cellpadding=5> <tr><th>Name</th><th>Size</th><th>Date</th></tr> <?php foreach($files as $name => $stats): ?> <tr> <td><?php print $name;?></td> <td><?php print $stats['size']; ?></td> <td><?php print date("m-d-Y h:ia", $stats['mtime']); ?></td> </tr> <?php endforeach; ?></table>


Tagged with..
#directories #files #ksort #php #read #stat #php

Just finishing up brewing up some fresh ground comments...