rawurlencode($part), $parts ) ); } function getFileIcon(string $filename): string { $extension = strtolower(pathinfo($filename, PATHINFO_EXTENSION)); return match ($extension) { 'jpg', 'jpeg', 'png', 'gif', 'webp', 'svg' => '🖼️', 'mp4', 'mkv', 'avi', 'mov', 'webm' => '🎬', 'mp3', 'wav', 'ogg', 'flac', 'aac' => '🎵', 'zip', 'rar', '7z', 'tar', 'gz' => '🗜️', 'pdf' => '📕', 'doc', 'docx', 'odt' => '📘', 'xls', 'xlsx', 'csv' => '📊', 'ppt', 'pptx' => '📙', 'php', 'js', 'ts', 'html', 'css', 'json', 'xml', 'rs', 'py' => '💻', 'txt', 'log', 'md' => '📄', default => '📄', }; } $items = scandir($currentDirectory); if ($items === false) { http_response_code(500); exit('Unable to read directory.'); } $directories = []; $files = []; foreach ($items as $name) { if (in_array($name, $ignoredNames, true)) { continue; } if (!$showHiddenFiles && str_starts_with($name, '.')) { continue; } $absolutePath = $currentDirectory . DIRECTORY_SEPARATOR . $name; if (is_link($absolutePath)) { continue; } $relativePath = ltrim( substr($absolutePath, strlen($baseDirectory)), DIRECTORY_SEPARATOR ); $item = [ 'name' => $name, 'absolutePath' => $absolutePath, 'relativePath' => str_replace( DIRECTORY_SEPARATOR, '/', $relativePath ), 'modified' => filemtime($absolutePath) ?: 0, ]; if (is_dir($absolutePath)) { $directories[] = $item; } elseif (is_file($absolutePath)) { $item['size'] = filesize($absolutePath) ?: 0; $files[] = $item; } } usort( $directories, static fn(array $a, array $b): int => strnatcasecmp($a['name'], $b['name']) ); usort( $files, static fn(array $a, array $b): int => strnatcasecmp($a['name'], $b['name']) ); $currentRelativePath = ltrim( substr($currentDirectory, strlen($baseDirectory)), DIRECTORY_SEPARATOR ); $currentRelativePath = str_replace( DIRECTORY_SEPARATOR, '/', $currentRelativePath ); $parentRelativePath = ''; if ($currentRelativePath !== '') { $parentRelativePath = dirname($currentRelativePath); if ($parentRelativePath === '.') { $parentRelativePath = ''; } } $breadcrumbParts = $currentRelativePath === '' ? [] : explode('/', $currentRelativePath); $baseUrlPath = rtrim( str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME'] ?? '')), '/' ); ?>
| Name | Size | Modified |
|---|---|---|
| — | — | |
| Folder | = date( 'Y-m-d H:i:s', $directory['modified'] ) ?> | |
|
= getFileIcon($file['name']) ?>
= htmlspecialchars(
$file['name'],
ENT_QUOTES,
'UTF-8'
) ?>
|
= formatBytes($file['size']) ?> | = date( 'Y-m-d H:i:s', $file['modified'] ) ?> |