Directory Listing — List all files in a directory

Here’s a small snip­pet to iter­ate through an array and get all files in it as an array

function listDir ($dir)
{
$files = array();
$handle = opendir($dir);

while ($file = readdir($handler)) {
if ($file != '.' && $file != '..')
$files[] = $file;
}

closedir($handle);

return $files;
}

Leave a Reply