<?php
// Konfiguracja
define('UPLOAD_DIR', __DIR__ . '/upload/');
define('MAX_FILE_SIZE', 50 * 1024 * 1024); // 50MB
define('ALLOWED_EXTENSIONS', ['txt', 'log', 'csv', 'json', 'xml', 'zip', 'gz']);

// Tworzenie katalogu jeśli nie istnieje
if (!is_dir(UPLOAD_DIR)) {
    mkdir(UPLOAD_DIR, 0755, true);
}

$response = ['success' => false, 'message' => '', 'files' => []];

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['files'])) {
    $uploaded = [];
    $errors = [];
    $files = $_FILES['files'];

    // Normalizacja struktury $_FILES dla wielu plików
    $fileList = [];
    if (is_array($files['name'])) {
        for ($i = 0; $i < count($files['name']); $i++) {
            $fileList[] = [
                'name'     => $files['name'][$i],
                'type'     => $files['type'][$i],
                'tmp_name' => $files['tmp_name'][$i],
                'error'    => $files['error'][$i],
                'size'     => $files['size'][$i],
            ];
        }
    } else {
        $fileList[] = $files;
    }

    foreach ($fileList as $file) {
        if ($file['error'] !== UPLOAD_ERR_OK) {
            $errors[] = htmlspecialchars($file['name']) . ': błąd przesyłania';
            continue;
        }
        if ($file['size'] > MAX_FILE_SIZE) {
            $errors[] = htmlspecialchars($file['name']) . ': plik za duży (max 50MB)';
            continue;
        }
        $ext = strtolower(pathinfo($file['name'], PATHINFO_EXTENSION));
        if (!in_array($ext, ALLOWED_EXTENSIONS)) {
            $errors[] = htmlspecialchars($file['name']) . ': niedozwolone rozszerzenie';
            continue;
        }
        // Sanitize filename
        $safeName = preg_replace('/[^a-zA-Z0-9_\-\.]/', '_', $file['name']);
        $dest = UPLOAD_DIR . $safeName;
        // Avoid overwrite
        if (file_exists($dest)) {
            $safeName = time() . '_' . $safeName;
            $dest = UPLOAD_DIR . $safeName;
        }
        if (move_uploaded_file($file['tmp_name'], $dest)) {
            $uploaded[] = [
                'name' => $safeName,
                'size' => $file['size'],
            ];
        } else {
            $errors[] = htmlspecialchars($file['name']) . ': nie można zapisać pliku';
        }
    }

    $response['success'] = count($uploaded) > 0;
    $response['files'] = $uploaded;
    $response['message'] = count($uploaded) . ' plik(ów) przesłano pomyślnie.';
    if ($errors) {
        $response['errors'] = $errors;
    }

    header('Content-Type: application/json');
    echo json_encode($response);
    exit;
}

// Lista plików w katalogu upload
$existingFiles = [];
if (is_dir(UPLOAD_DIR)) {
    foreach (scandir(UPLOAD_DIR) as $f) {
        if ($f === '.' || $f === '..') continue;
        $existingFiles[] = [
            'name' => $f,
            'size' => filesize(UPLOAD_DIR . $f),
            'time' => filemtime(UPLOAD_DIR . $f),
        ];
    }
    usort($existingFiles, fn($a, $b) => $b['time'] - $a['time']);
}

function formatSize($bytes) {
    if ($bytes >= 1048576) return round($bytes / 1048576, 2) . ' MB';
    if ($bytes >= 1024) return round($bytes / 1024, 1) . ' KB';
    return $bytes . ' B';
}
?>
<!DOCTYPE html>
<html lang="pl">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Uploader Plików</title>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700&family=Syne:wght@400;600;800&display=swap" rel="stylesheet">
<style>
  *, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

  :root {
    --bg: #0a0c10;
    --surface: #11141a;
    --surface2: #181c24;
    --border: #252a36;
    --accent: #00e5a0;
    --accent2: #00b8ff;
    --accent-dim: rgba(0, 229, 160, 0.08);
    --accent-glow: rgba(0, 229, 160, 0.25);
    --text: #e8ecf4;
    --text-dim: #6b7280;
    --error: #ff4d6d;
    --warning: #ffb547;
    --mono: 'JetBrains Mono', monospace;
    --sans: 'Syne', sans-serif;
  }

  html, body {
    min-height: 100vh;
    background: var(--bg);
    color: var(--text);
    font-family: var(--mono);
  }

  body {
    background-image:
      radial-gradient(ellipse 80% 50% at 50% -20%, rgba(0,229,160,0.07) 0%, transparent 60%),
      radial-gradient(ellipse 60% 40% at 80% 80%, rgba(0,184,255,0.05) 0%, transparent 60%);
    padding: 40px 20px 60px;
  }

  .container {
    max-width: 780px;
    margin: 0 auto;
  }

  header {
    display: flex;
    align-items: flex-end;
    gap: 16px;
    margin-bottom: 40px;
  }

  .logo-box {
    width: 52px; height: 52px;
    border: 2px solid var(--accent);
    border-radius: 10px;
    display: grid;
    place-items: center;
    box-shadow: 0 0 20px var(--accent-glow), inset 0 0 20px rgba(0,229,160,0.05);
    flex-shrink: 0;
  }

  .logo-box svg { width: 26px; height: 26px; }

  .header-text h1 {
    font-family: var(--sans);
    font-size: 1.75rem;
    font-weight: 800;
    letter-spacing: -0.02em;
    line-height: 1;
    background: linear-gradient(135deg, #fff 40%, var(--accent));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
  }

  .header-text p {
    font-size: 0.72rem;
    color: var(--text-dim);
    margin-top: 4px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
  }

  /* Drop Zone */
  .drop-zone {
    border: 2px dashed var(--border);
    border-radius: 16px;
    padding: 56px 32px;
    text-align: center;
    cursor: pointer;
    position: relative;
    transition: border-color 0.25s, background 0.25s, transform 0.2s;
    background: var(--surface);
    user-select: none;
    overflow: hidden;
  }

  .drop-zone::before {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 50% 50%, var(--accent-dim) 0%, transparent 70%);
    opacity: 0;
    transition: opacity 0.3s;
    pointer-events: none;
  }

  .drop-zone.drag-over {
    border-color: var(--accent);
    background: #0e1218;
    transform: scale(1.01);
  }
  .drop-zone.drag-over::before { opacity: 1; }

  .drop-icon {
    width: 56px; height: 56px;
    border-radius: 14px;
    background: var(--accent-dim);
    border: 1px solid rgba(0,229,160,0.2);
    display: inline-grid;
    place-items: center;
    margin-bottom: 18px;
    transition: transform 0.2s, box-shadow 0.2s;
  }

  .drop-zone.drag-over .drop-icon {
    transform: translateY(-4px);
    box-shadow: 0 12px 30px var(--accent-glow);
  }

  .drop-icon svg { width: 28px; height: 28px; color: var(--accent); }

  .drop-title {
    font-family: var(--sans);
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 8px;
  }

  .drop-sub {
    font-size: 0.72rem;
    color: var(--text-dim);
    letter-spacing: 0.05em;
    line-height: 1.6;
  }

  .drop-sub span { color: var(--accent); }

  #fileInput { display: none; }

  /* Queue */
  .queue { margin-top: 20px; display: flex; flex-direction: column; gap: 8px; }

  .queue-item {
    display: flex; align-items: center; gap: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 10px 14px;
    animation: slideIn 0.25s ease;
  }

  @keyframes slideIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
  }

  .queue-item .file-icon {
    width: 34px; height: 34px; border-radius: 8px;
    background: var(--accent-dim);
    border: 1px solid rgba(0,229,160,0.15);
    display: grid; place-items: center; flex-shrink: 0;
  }

  .queue-item .file-icon svg { width: 16px; height: 16px; color: var(--accent); }
  .queue-item .file-name { flex: 1; font-size: 0.8rem; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .queue-item .file-size { font-size: 0.7rem; color: var(--text-dim); flex-shrink: 0; }
  .queue-item .remove-btn { background: none; border: none; cursor: pointer; color: var(--text-dim); padding: 4px; border-radius: 6px; transition: color 0.2s; flex-shrink: 0; }
  .queue-item .remove-btn:hover { color: var(--error); }

  .progress-bar-wrap { height: 2px; background: var(--border); border-radius: 2px; margin-top: 6px; }
  .progress-bar { height: 100%; border-radius: 2px; background: linear-gradient(90deg, var(--accent), var(--accent2)); width: 0%; transition: width 0.3s; }

  /* Buttons */
  .btn-row { display: flex; gap: 10px; margin-top: 16px; }

  .btn {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 11px 22px; border-radius: 10px; border: none;
    cursor: pointer; font-family: var(--mono); font-size: 0.78rem;
    font-weight: 500; letter-spacing: 0.04em;
    transition: all 0.2s; text-transform: uppercase;
  }

  .btn-primary {
    background: var(--accent);
    color: #050807;
    box-shadow: 0 0 20px var(--accent-glow);
  }
  .btn-primary:hover { background: #00ffb3; box-shadow: 0 0 30px rgba(0,255,179,0.4); transform: translateY(-1px); }
  .btn-primary:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }

  .btn-ghost {
    background: transparent;
    color: var(--text-dim);
    border: 1px solid var(--border);
  }
  .btn-ghost:hover { color: var(--text); border-color: #3a4052; background: var(--surface2); }

  /* Alerts */
  .alert {
    border-radius: 10px; padding: 12px 16px;
    font-size: 0.78rem; line-height: 1.6;
    display: none; margin-top: 14px;
    animation: slideIn 0.25s ease;
  }
  .alert.show { display: block; }
  .alert-success { background: rgba(0,229,160,0.08); border: 1px solid rgba(0,229,160,0.25); color: var(--accent); }
  .alert-error   { background: rgba(255,77,109,0.08); border: 1px solid rgba(255,77,109,0.25); color: var(--error); }
  .alert-error ul { padding-left: 16px; margin-top: 6px; }

  /* Divider */
  .divider {
    display: flex; align-items: center; gap: 12px;
    margin: 36px 0 24px; color: var(--text-dim);
    font-size: 0.68rem; letter-spacing: 0.12em; text-transform: uppercase;
  }
  .divider::before, .divider::after {
    content: ''; flex: 1; height: 1px; background: var(--border);
  }

  /* Files Table */
  .files-table { width: 100%; border-collapse: collapse; }

  .files-table th {
    text-align: left; font-size: 0.65rem; letter-spacing: 0.1em;
    text-transform: uppercase; color: var(--text-dim);
    padding: 8px 12px; border-bottom: 1px solid var(--border);
  }

  .files-table td {
    padding: 10px 12px; font-size: 0.75rem;
    border-bottom: 1px solid rgba(37,42,54,0.5);
    vertical-align: middle;
  }

  .files-table tr:last-child td { border-bottom: none; }

  .files-table tr { transition: background 0.15s; }
  .files-table tbody tr:hover { background: var(--surface2); }

  .file-badge {
    display: inline-block; padding: 2px 7px; border-radius: 5px;
    font-size: 0.62rem; font-weight: 700; text-transform: uppercase;
    background: var(--accent-dim); color: var(--accent); letter-spacing: 0.06em;
  }

  .file-name-cell { color: var(--text); font-size: 0.76rem; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .size-cell, .date-cell { color: var(--text-dim); white-space: nowrap; }

  .download-link {
    color: var(--accent2); text-decoration: none; font-size: 0.72rem;
    display: inline-flex; align-items: center; gap: 4px;
    transition: color 0.2s;
  }
  .download-link:hover { color: #5fd3ff; }

  .empty-state {
    text-align: center; padding: 40px 20px;
    color: var(--text-dim); font-size: 0.75rem;
    letter-spacing: 0.06em;
  }

  .card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    overflow: hidden;
  }

  /* Loader spinner */
  .spinner {
    width: 14px; height: 14px;
    border: 2px solid rgba(5,8,7,0.3);
    border-top-color: #050807;
    border-radius: 50%;
    animation: spin 0.7s linear infinite;
    display: none;
  }
  @keyframes spin { to { transform: rotate(360deg); } }

  /* Stats bar */
  .stats-bar {
    display: flex; gap: 20px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 14px 20px;
    margin-bottom: 12px;
    font-size: 0.7rem; color: var(--text-dim);
  }
  .stat { display: flex; flex-direction: column; gap: 2px; }
  .stat strong { font-size: 0.95rem; color: var(--text); font-family: var(--sans); font-weight: 600; }
</style>
</head>
<body>
<div class="container">

  <header>
    <div class="logo-box">
      <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round" style="color:var(--accent)">
        <path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/>
        <polyline points="17 8 12 3 7 8"/>
        <line x1="12" y1="3" x2="12" y2="15"/>
      </svg>
    </div>
    <div class="header-text">
      <h1>File Uploader</h1>
      <p>Przesyłanie plików · katalog /upload</p>
    </div>
  </header>

  <!-- Drop Zone -->
  <div class="drop-zone" id="dropZone">
    <input type="file" id="fileInput" multiple accept=".txt,.log,.csv,.json,.xml,.zip,.gz">
    <div class="drop-icon">
      <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
        <polyline points="16 16 12 12 8 16"/>
        <line x1="12" y1="12" x2="12" y2="21"/>
        <path d="M20.39 18.39A5 5 0 0 0 18 9h-1.26A8 8 0 1 0 3 16.3"/>
      </svg>
    </div>
    <p class="drop-title">Przeciągnij pliki tutaj lub kliknij aby wybrać</p>
    <p class="drop-sub">
      Obsługiwane: <span>txt, log, csv, json, xml, zip, gz</span><br>
      Maksymalny rozmiar: <span>50 MB</span> · Wiele plików jednocześnie
    </p>
  </div>

  <div class="queue" id="fileQueue"></div>

  <div class="btn-row" id="btnRow" style="display:none">
    <button class="btn btn-primary" id="uploadBtn">
      <svg width="15" height="15" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="17 8 12 3 7 8"/><line x1="12" y1="3" x2="12" y2="15"/></svg>
      <span class="spinner" id="spinner"></span>
      <span id="uploadLabel">Wyślij pliki</span>
    </button>
    <button class="btn btn-ghost" id="clearBtn">Wyczyść</button>
  </div>

  <div class="alert alert-success" id="alertSuccess"></div>
  <div class="alert alert-error" id="alertError"></div>

  <!-- Existing files -->
  <div class="divider">Przesłane pliki</div>

  <?php
  $totalSize = array_sum(array_column($existingFiles, 'size'));
  ?>
  <div class="stats-bar">
    <div class="stat"><strong><?= count($existingFiles) ?></strong><span>pliki</span></div>
    <div class="stat"><strong><?= formatSize($totalSize) ?></strong><span>łącznie</span></div>
    <div class="stat"><strong><?= date('d.m.Y') ?></strong><span>dzisiaj</span></div>
  </div>

  <div class="card">
    <table class="files-table" id="filesTable">
      <thead>
        <tr>
          <th>Typ</th>
          <th>Nazwa pliku</th>
          <th>Rozmiar</th>
          <th>Data</th>
          <th></th>
        </tr>
      </thead>
      <tbody id="filesBody">
        <?php if (empty($existingFiles)): ?>
        <tr><td colspan="5"><div class="empty-state">Brak przesłanych plików</div></td></tr>
        <?php else: foreach ($existingFiles as $f):
          $ext = strtolower(pathinfo($f['name'], PATHINFO_EXTENSION)); ?>
        <tr>
          <td><span class="file-badge"><?= htmlspecialchars($ext) ?: '???' ?></span></td>
          <td class="file-name-cell" title="<?= htmlspecialchars($f['name']) ?>"><?= htmlspecialchars($f['name']) ?></td>
          <td class="size-cell"><?= formatSize($f['size']) ?></td>
          <td class="date-cell"><?= date('d.m.Y H:i', $f['time']) ?></td>
          <td>
            <a class="download-link" href="upload/<?= rawurlencode($f['name']) ?>" download>
              <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
              Pobierz
            </a>
          </td>
        </tr>
        <?php endforeach; endif; ?>
      </tbody>
    </table>
  </div>
</div>

<script>
const dropZone   = document.getElementById('dropZone');
const fileInput  = document.getElementById('fileInput');
const fileQueue  = document.getElementById('fileQueue');
const btnRow     = document.getElementById('btnRow');
const uploadBtn  = document.getElementById('uploadBtn');
const clearBtn   = document.getElementById('clearBtn');
const spinner    = document.getElementById('spinner');
const uploadLabel= document.getElementById('uploadLabel');
const alertOk    = document.getElementById('alertSuccess');
const alertErr   = document.getElementById('alertError');
const filesBody  = document.getElementById('filesBody');

const MAX_SIZE   = 50 * 1024 * 1024;
const ALLOWED    = ['txt','log','csv','json','xml','zip','gz'];

let selectedFiles = [];

dropZone.addEventListener('click', () => fileInput.click());
fileInput.addEventListener('change', e => addFiles(e.target.files));

dropZone.addEventListener('dragover',  e => { e.preventDefault(); dropZone.classList.add('drag-over'); });
dropZone.addEventListener('dragleave', () => dropZone.classList.remove('drag-over'));
dropZone.addEventListener('drop', e => {
  e.preventDefault();
  dropZone.classList.remove('drag-over');
  addFiles(e.dataTransfer.files);
});

function ext(name) { return name.split('.').pop().toLowerCase(); }

function formatSize(bytes) {
  if (bytes >= 1048576) return (bytes/1048576).toFixed(2) + ' MB';
  if (bytes >= 1024)    return (bytes/1024).toFixed(1) + ' KB';
  return bytes + ' B';
}

function addFiles(fileList) {
  Array.from(fileList).forEach(file => {
    const e = ext(file.name);
    if (!ALLOWED.includes(e)) { showError([`${file.name}: niedozwolone rozszerzenie`]); return; }
    if (file.size > MAX_SIZE) { showError([`${file.name}: plik za duży`]); return; }
    if (selectedFiles.find(f => f.name === file.name && f.size === file.size)) return;
    selectedFiles.push(file);
    renderQueue();
  });
  fileInput.value = '';
}

function renderQueue() {
  fileQueue.innerHTML = '';
  selectedFiles.forEach((file, i) => {
    const item = document.createElement('div');
    item.className = 'queue-item';
    item.innerHTML = `
      <div class="file-icon">
        <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round">
          <path d="M13 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V9z"/>
          <polyline points="13 2 13 9 20 9"/>
        </svg>
      </div>
      <span class="file-name" title="${file.name}">${file.name}</span>
      <span class="file-size">${formatSize(file.size)}</span>
      <button class="remove-btn" data-idx="${i}" title="Usuń">
        <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/></svg>
      </button>
      <div style="position:absolute;bottom:0;left:0;right:0" class="progress-bar-wrap" id="prog-${i}"><div class="progress-bar" id="bar-${i}"></div></div>
    `;
    item.style.position = 'relative';
    fileQueue.appendChild(item);
  });
  btnRow.style.display = selectedFiles.length ? 'flex' : 'none';

  document.querySelectorAll('.remove-btn').forEach(btn => {
    btn.addEventListener('click', () => {
      selectedFiles.splice(+btn.dataset.idx, 1);
      renderQueue();
    });
  });
}

clearBtn.addEventListener('click', () => {
  selectedFiles = [];
  renderQueue();
  hideAlerts();
});

uploadBtn.addEventListener('click', uploadFiles);

function setLoading(on) {
  uploadBtn.disabled = on;
  spinner.style.display = on ? 'block' : 'none';
  uploadLabel.textContent = on ? 'Wysyłanie...' : 'Wyślij pliki';
}

function hideAlerts() {
  alertOk.classList.remove('show');
  alertErr.classList.remove('show');
}

function showError(msgs) {
  alertErr.innerHTML = 'Błędy:<ul>' + msgs.map(m => `<li>${m}</li>`).join('') + '</ul>';
  alertErr.classList.add('show');
}

async function uploadFiles() {
  if (!selectedFiles.length) return;
  hideAlerts();
  setLoading(true);

  const formData = new FormData();
  selectedFiles.forEach(f => formData.append('files[]', f));

  try {
    const res = await fetch(location.href, { method: 'POST', body: formData });
    const data = await res.json();

    if (data.success) {
      alertOk.textContent = '✓ ' + data.message;
      alertOk.classList.add('show');
      data.files.forEach(f => prependRow(f));
      selectedFiles = [];
      renderQueue();
    } else {
      showError(data.errors || ['Nieznany błąd']);
    }
    if (data.errors && data.success) showError(data.errors);

  } catch (e) {
    showError(['Błąd połączenia z serwerem']);
  } finally {
    setLoading(false);
  }
}

function prependRow(file) {
  const e = file.name.split('.').pop();
  const now = new Date();
  const pad = n => String(n).padStart(2,'0');
  const date = `${pad(now.getDate())}.${pad(now.getMonth()+1)}.${now.getFullYear()} ${pad(now.getHours())}:${pad(now.getMinutes())}`;

  // Remove empty state row if present
  const emptyRow = filesBody.querySelector('td[colspan]');
  if (emptyRow) emptyRow.closest('tr').remove();

  const tr = document.createElement('tr');
  tr.style.animation = 'slideIn 0.3s ease';
  tr.innerHTML = `
    <td><span class="file-badge">${e}</span></td>
    <td class="file-name-cell" title="${file.name}">${file.name}</td>
    <td class="size-cell">${formatSize(file.size)}</td>
    <td class="date-cell">${date}</td>
    <td><a class="download-link" href="upload/${encodeURIComponent(file.name)}" download>
      <svg width="13" height="13" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.2" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"/><polyline points="7 10 12 15 17 10"/><line x1="12" y1="15" x2="12" y2="3"/></svg>
      Pobierz
    </a></td>
  `;
  filesBody.prepend(tr);
}
</script>
</body>
</html>