Browse Source

implement directory listing navigation

nex-php
yggverse 7 months ago
parent
commit
1723cd3ed1
  1. 29
      src/nex.php

29
src/nex.php

@ -220,11 +220,28 @@ $server->start(
foreach ((array) scandir($goal) as $link) foreach ((array) scandir($goal) as $link)
{ {
// Skip hidden entities and make sure the destination is accessible // Skip system entities
if (!str_starts_with($link, '.') && is_readable($goal . $link)) if (str_starts_with($link, '.'))
{ {
// Keep parent navigation entities only
if ($link == '..' && $parent = realpath($goal . $link))
{
if (str_starts_with($parent . DIRECTORY_SEPARATOR, NEXT_PATH))
{
if (is_readable($parent))
{
$links[] = '=> ../';
}
}
}
continue;
}
// Directory // Directory
if (is_dir($link)) if (is_dir($goal . $link))
{
if (is_readable($goal . $link))
{ {
$links[] = sprintf( $links[] = sprintf(
'=> %s/', '=> %s/',
@ -234,8 +251,11 @@ $server->start(
); );
} }
continue;
}
// File // File
else if (is_readable($goal . $link))
{ {
$links[] = sprintf( $links[] = sprintf(
'=> %s', '=> %s',
@ -245,7 +265,6 @@ $server->start(
); );
} }
} }
}
$response = implode( $response = implode(
PHP_EOL, PHP_EOL,

Loading…
Cancel
Save