Scandir - List files and directories inside the specified path

$cdir = scandir($dir);

foreach ($cdir as $key => $value){ if (!in_array($value,array('.',..))) { if (is_dir($dir . DIRECTORY_SEPARATOR . $value)) { $result[dir][] = $dir . DIRECTORY_SEPARATOR . $value; } else { $result[file][] = $value.' - '.getExtension($value); } }}

function getExtension($a){$a = stripslashes($a);$dot = strtolower(substr (strrchr ($a, '.'), 1));return $dot;}