. * * This software is best enjoyed with soused herring! */ // Configuration: // List of filenames (and folder names) that should be ignored. $ignore_file_list = [ 'dirlistozxa.php', 'gen-thumbs' // dirlistozxa ]; // ================ // Lazy sanitisation done if the web server somehow sends idiotic input, // nginx with default configuration (merge_slashes) doesn't actually need this. $_SERVER['REQUEST_URI'] = str_replace('../', '', $_SERVER['REQUEST_URI']); // Allow spaces and other heretical stuff in folder names. $_SERVER['REQUEST_URI'] = urldecode($_SERVER['REQUEST_URI']); $folder = str_replace('?'.$_SERVER['QUERY_STRING'], '', $_SERVER['REQUEST_URI']); $path = $_SERVER['DOCUMENT_ROOT'].$folder; if (!is_dir($path)) die('invalid folder?'); define('THUMB_FOLDER', 1); define('THUMB_FILE', 2); define('THUMB_IMAGE', 3); function display_size($bytes, $precision = 2) { $units = ['B', 'K', 'M', 'G', 'T']; $bytes = max($bytes, 0); $pow = floor(($bytes ? log($bytes) : 0) / log(1024)); $pow = min($pow, count($units) - 1); $bytes /= (1 << (10 * $pow)); return round($bytes, $precision) . $units[$pow]; } function row($name, $date, $size, $thumb) { $img = match ($thumb) { THUMB_FOLDER => '/.dirlistozxa/folder.png', THUMB_FILE => '/.dirlistozxa/file.png', THUMB_IMAGE => "/.thumbs/".$name, }; return sprintf( ' %s %s%s ', $name, $img, $name, $name, $date, $size); } function build_blocks($items) { global $ignore_file_list, $path, $folder; $rtn = ''; $objects = [ 'directories' => [], 'files' => [] ]; foreach ($items as $item) { if (in_array($item, $ignore_file_list) || str_starts_with($item, '.')) continue; if (is_dir($path.$item)) $objects['directories'][$item] = $item; else $objects['files'][$item] = $item; } // SORT natsort($objects['directories']); natsort($objects['files']); if ($folder != '/') $rtn .= row('../', '', '', THUMB_FOLDER); foreach ($objects['directories'] as $dir) { $name = basename($dir).'/'; $date = date('Y-m-d H:i', filemtime($path.$dir)); $rtn .= row($name, $date, '-', THUMB_FOLDER); } foreach ($objects['files'] as $file) { $name = basename($file); $date = date('Y-m-d H:i', filemtime($path.$file)); $size = display_size(filesize($path.$file)); $doThumb = file_exists($_SERVER['DOCUMENT_ROOT']."/.thumbs/".$file) ? THUMB_IMAGE : THUMB_FILE; $rtn .= row($name, $date, $size, $doThumb); } return $rtn; } ?> Index of <?=$folder ?>

Index of

NameLast modifiedSize


server at , index powered by dirlistozxa