Skip to content

Commit

Permalink
Enhance ordering and avoid try get broken symlink
Browse files Browse the repository at this point in the history
  • Loading branch information
natanfelles committed Jan 16, 2018
1 parent 2d79174 commit 5b77b74
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
13 changes: 10 additions & 3 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,6 @@
usort($paths, function ($path1, $path2) {
$order_by = $_GET['order_by'];

$path1['mTime'] = strtotime($path1['mTime']);
$path2['mTime'] = strtotime($path2['mTime']);

if ($path1[$order_by] === $path2[$order_by])
{
return 0;
Expand All @@ -133,5 +130,15 @@
$paths = array_reverse($paths);
}

$count = count($paths);

for ($i = 0; $i < $count; $i++)
{
$paths[$i]['mTime'] = date('Y-m-d H:i:s', $paths[$i]['mTime']);
$paths[$i]['size'] = strpos($paths[$i]['size'], 'item') !== false
? $paths[$i]['size']
: $GLOBALS['function_size_conversion']($paths[$i]['size']);
}

return $paths;
};
9 changes: 7 additions & 2 deletions src/server_router.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,11 @@

foreach ($filesystem as $pathname => $SplFileInfo)
{
if (! file_exists($SplFileInfo->getRealPath()))
{
continue;
}

if ($SplFileInfo->isDir())
{
$fi = new FilesystemIterator($SplFileInfo->getRealPath());
Expand All @@ -117,11 +122,11 @@
'realPath' => $SplFileInfo->getRealPath(),
'filename' => $SplFileInfo->getFilename(),
'isDir' => $SplFileInfo->isDir(),
'size' => $SplFileInfo->isDir() ? iterator_count($fi) . ' items' : $function_size_conversion($SplFileInfo->getSize()),
'size' => $SplFileInfo->isDir() ? iterator_count($fi) . ' items' : $SplFileInfo->getSize(),
'owner' => $SplFileInfo->getOwner(),
'group' => $SplFileInfo->getGroup(),
'perms' => substr(sprintf('%o', $SplFileInfo->getPerms()), -4),
'mTime' => date('Y-m-d H:i:s', $SplFileInfo->getMTime()),
'mTime' => $SplFileInfo->getMTime(),
'href' => $function_path_href($SplFileInfo),
];
}
Expand Down

0 comments on commit 5b77b74

Please sign in to comment.