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

Apps I've Built

PhotoLocationChanger
Easily change the location on your photos and videos
Click here for more info about the app
PhotoDateChanger
Easily change the dates and times on your photos and videos
Click here for more info about the app
VocabReminder
English dictionary with notifications so you won't forget what you're studying!
Click here for more info about the app
VocabQuiz
The app that quizzes and scores you on your vocabulary!
Click here for more info about the app