&1", $out, $ret); if ($ret !== 0 || !file_exists($tmp)) { http_response_code(500); exit('failed to create archive. please open an issue.'); } header('Content-Type: application/x-xz'); header('Content-Disposition: attachment; filename="unimg-source.tar.xz"'); header('Content-Length: ' . filesize($tmp)); readfile($tmp); unlink($tmp); exit; } if ($action === 'raw') { if ($real === false || !is_file($real)) { http_response_code(404); exit('file not found'); } header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . basename($real) . '"'); header('Content-Length: ' . filesize($real)); readfile($real); exit; } function fmt_size(int $bytes): string { if ($bytes === 0) return '0 B'; $u = ['B','KB','MB','GB','TB']; $i = (int) floor(log($bytes, 1024)); return round($bytes / pow(1024, $i), 1) . ' ' . $u[$i]; } function fmt_date(int $ts): string { return date('d.m.Y', $ts); } function render_md(string $src): string { $lines = explode("\n", $src); $html = ''; $inCode = false; $inList = false; $inline = function(string $line) : string { $line = preg_replace('/`([^`]+)`/', '$1', $line); $line = preg_replace('/!\[([^\]]*)\]\(([^)]+)\)/', '$1', $line); $line = preg_replace('/\[([^\]]+)\]\(([^)]+)\)/', '$1', $line); $line = preg_replace('/\*\*(.+?)\*\*/', '$1', $line); $line = preg_replace('/\*(.+?)\*/', '$1', $line); return $line; }; foreach ($lines as $line) { if (preg_match('/^```/', $line)) { if ($inCode) { $html .= ''; $inCode = false; } else { if ($inList) { $html .= ''; $inList = false; } $html .= '
';
                $inCode = true;
            }
            continue;
        }
        if ($inCode) {
            $html .= htmlspecialchars($line) . "\n";
            continue;
        }

        $trimmed = rtrim($line);

        if ($trimmed === '') {
            if ($inList) { $html .= ''; $inList = false; }
            $html .= "\n";
            continue;
        }

        if (preg_match('/^---+$/', $trimmed)) {
            if ($inList) { $html .= ''; $inList = false; }
            $html .= '
'; continue; } if (preg_match('/^(#{1,6})\s+(.*)$/', $trimmed, $m)) { if ($inList) { $html .= ''; $inList = false; } $lvl = strlen($m[1]); $tag = 'h' . min($lvl + 1, 6); $html .= '<' . $tag . ' style="font-size:14px;font-weight:normal;text-transform:lowercase;margin:1.8em 0 0.6em 0;color:#fff">' . $inline($m[2]) . ''; continue; } if (preg_match('/^[\-\*]\s+(.*)$/', $trimmed, $m)) { if (!$inList) { $html .= ''; $inList = false; } $html .= '

' . $inline($trimmed) . '

'; } if ($inCode) $html .= '
'; if ($inList) $html .= ''; return $html; } ?> <?= htmlspecialchars($SITE_TITLE) ?>
   __  __      ______  _________
  / / / /___  /  _/  |/  / ____/
 / / / / __ \ / // /|_/ / / __  
/ /_/ / / / // // /  / / /_/ /  
\____/_/ /_/___/_/  /_/\____/   
                                
file not found: ' . htmlspecialchars($path) . '

'; } else { $name = basename($real); $dir = dirname($path); $parent = ($dir === '.' || $dir === '') ? '' : $dir; $isMd = preg_match('/\.md$/i', $name); $isXz = preg_match('/\.xz$/i', $name); if ($isXz) { header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . $name . '"'); header('Content-Length: ' . filesize($real)); readfile($real); exit; } $parts = array_filter(explode('/', $path)); echo '

'; echo '/'; $acc = ''; $last = array_pop($parts); foreach ($parts as $p) { $acc .= ($acc ? '/' : '') . $p; echo '' . htmlspecialchars($p) . '/'; } echo '' . htmlspecialchars($last) . ''; echo '

'; $backHref = $parent ? '?p=' . urlencode($parent) : '?'; echo '

'; echo '← back'; echo ' | ↓ download ' . htmlspecialchars($name) . ''; echo '

'; $content = file_get_contents($real); if ($isMd) { echo '
' . render_md($content) . '
'; } else { echo '
' . htmlspecialchars($content) . '
'; } echo '

' . fmt_size(filesize($real)) . '

'; } } else { echo '

↓ download all as .tar.xz

'; $target = $path === '' ? $SOURCE_DIR : $full; if (!is_dir($target)) { echo '

directory not found.

'; } else { echo '

'; echo '/'; if ($path !== '') { $parts = array_filter(explode('/', $path)); $acc = ''; foreach ($parts as $p) { $acc .= ($acc ? '/' : '') . $p; echo '' . htmlspecialchars($p) . '/'; } } echo '

'; $items = scandir($target); $dirs = []; $files = []; foreach ($items as $item) { if ($item === '.' || $item === '..') continue; $fp = $target . '/' . $item; $rp = $path === '' ? $item : $path . '/' . $item; $st = stat($fp); $entry = [ 'name' => $item, 'rel' => $rp, 'dir' => is_dir($fp), 'size' => is_dir($fp) ? 0 : $st['size'], 'mod' => $st['mtime'], ]; if ($entry['dir']) $dirs[] = $entry; else $files[] = $entry; } usort($dirs, fn($a,$b) => strcasecmp($a['name'], $b['name'])); usort($files, fn($a,$b) => strcasecmp($a['name'], $b['name'])); $all = array_merge($dirs, $files); if (empty($all) && $path === '') { echo '

the source directory is empty.

'; } else { echo ''; echo ''; echo ''; echo ''; echo ''; echo ''; if ($path !== '') { $pp = dirname($path); $ph = ($pp === '.' || $pp === '') ? '?' : '?p=' . urlencode($pp); echo ''; echo ''; echo ''; echo ''; echo ''; } foreach ($all as $e) { $isXzFile = !$e['dir'] && preg_match('/\.xz$/i', $e['name']); echo ''; if ($e['dir']) { echo ''; echo ''; } elseif ($isXzFile) { echo ''; echo ''; } else { echo ''; echo ''; } echo ''; echo ''; } echo '
namesizemodified
📁 ..
'; echo '📁 ' . htmlspecialchars($e['name']) . '/'; echo ''; echo '📄 ' . htmlspecialchars($e['name']) . ''; echo '' . fmt_size($e['size']) . ''; echo '📄 ' . htmlspecialchars($e['name']) . ''; echo '' . fmt_size($e['size']) . '' . fmt_date($e['mod']) . '
'; $dc = count($dirs); $fc = count($files); echo '

'; echo $dc . ' ' . ($dc === 1 ? 'directory' : 'directories') . ', '; echo $fc . ' ' . ($fc === 1 ? 'file' : 'files'); echo '

'; } } } ?>

© 2026 vextoly ยท source