Posts Tagged ‘ksort’

Listing Files and Directories with PHP

Posted 27 Jan 2010 — by admin
Category php

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>