. * * 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( '
Name | Last modified | Size | |
---|---|---|---|