VocabReminder
Easily build a great vocabulary without studying! Now on the App Store!
Click here for more info about the app

Listing Files and Directories with 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>

Tagged w/ #directories #files #ksort #php #read #statphp