<?php
/**
* List directory files
*
* @param $directory
* @return array
* @throws Exception
*/
function listFiles($directory)
{
$result = [];
if (is_dir($directory)) {
if ($handle = opendir($directory)) {
while (false !== ($entry = readdir($handle))) {
if ($entry != "." && $entry != ".." && $entry != ".htaccess") {
$result[] = $entry;
}
}
asort($result);
} else {
throw new Exception('Can\'t open directory "' . $directory . '"');
}
} else {
throw new Exception('Directory "' . $directory . '" not found');
}
return $result;
}
foreach (listFiles('.') AS $file) {
$ext = explode('.', $file);
$ext = end($ext);
echo str_replace('.' . $ext, '', $file) . '<br/>';
}
/*
favicon
index
robots
test
web
*/