The other day the new developer in my office wanted to get a directory listing using PHP as he was writting a new plugin for WordPress. To his surprise this is really easy with the glob() function:
<?php foreach (glob("*") as $filename) { echo $filename . 'size ' . filesize($filename) . 'n'; }
Glob allows you to use patterns similar to those when you are using the ls command in Terminal and returns the file list as an array.