Browse Source

implement directory listing navigation

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

45
src/nex.php

@ -220,30 +220,49 @@ $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, '.'))
{ {
// Directory // Keep parent navigation entities only
if (is_dir($link)) if ($link == '..' && $parent = realpath($goal . $link))
{ {
$links[] = sprintf( if (str_starts_with($parent . DIRECTORY_SEPARATOR, NEXT_PATH))
'=> %s/', {
urlencode( if (is_readable($parent))
$link {
) $links[] = '=> ../';
); }
}
} }
// File continue;
else }
// Directory
if (is_dir($goal . $link))
{
if (is_readable($goal . $link))
{ {
$links[] = sprintf( $links[] = sprintf(
'=> %s', '=> %s/',
urlencode( urlencode(
$link $link
) )
); );
} }
continue;
}
// File
if (is_readable($goal . $link))
{
$links[] = sprintf(
'=> %s',
urlencode(
$link
)
);
} }
} }

Loading…
Cancel
Save