<?php
/* ============== TEMEL AYARLAR ============== */
const PANEL_PASSWORD = '';           // İsteğe bağlı parola (boş = kapalı)
$allowedMime = ['application/pdf','image/jpeg','image/png'];
const MAX_SIZE = 10 * 1024 * 1024;   // 10 MB
/* =========================================== */

/* --- 1) Basit HTTP Auth ---------------------------------------------------- */
if (PANEL_PASSWORD !== '') {
    if (!isset($_SERVER['PHP_AUTH_PW']) || $_SERVER['PHP_AUTH_PW'] !== PANEL_PASSWORD) {
        header('WWW-Authenticate: Basic realm="Arşiv"');
        header('HTTP/1.0 401 Unauthorized');  exit('Yetkisiz erişim!');
    }
}

/* --- 2) Silme -------------------------------------------------------------- */
if (isset($_GET['action'], $_GET['f']) && $_GET['action']==='delete') {
    $file = basename($_GET['f']);
    if ($file && is_file($file)) { unlink($file); }
    header('Location: '.$_SERVER['PHP_SELF']); exit;
}

/* --- 3) Yükleme ------------------------------------------------------------ */
$msg = '';
if ($_SERVER['REQUEST_METHOD']==='POST' && isset($_FILES['dosya'])) {
    $f = $_FILES['dosya'];
    if ($f['error']!==UPLOAD_ERR_OK)                $msg='Yükleme hatası: '.$f['error'];
    elseif ($f['size']>MAX_SIZE)                   $msg='Dosya çok büyük (>'.(MAX_SIZE/1048576).' MB)';
    elseif ($allowedMime && !in_array(mime_content_type($f['tmp_name']),$allowedMime))
                                                    $msg='Dosya türüne izin verilmiyor';
    elseif (file_exists($f['name']))                $msg='Aynı isimde dosya var';
    else { move_uploaded_file($f['tmp_name'],$f['name']); $msg='Yükleme başarılı!'; }
}

/* --- 4) Dosya listesi (index.php gizlenir) --------------------------------- */
$script = basename(__FILE__);
$files = array_filter(scandir(__DIR__), fn($f)=>
    is_file($f) && $f!==$script                      // <- index.php gizli
);
usort($files, fn($a,$b)=>filemtime($b)<=>filemtime($a));

/* --- 5) HTML --------------------------------------------------------------- */
?><!doctype html><html lang="tr"><head><meta charset="utf-8">
<title>Arşiv</title>
<style>
body{margin:0;font-family:system-ui,Arial;background:#359c46;color:#222}
.box{max-width:750px;margin:40px auto;background:#fff;border-radius:6px;
     box-shadow:0 4px 12px rgba(0,0,0,.15);overflow:hidden}
h1{margin:0;padding:16px 24px;background:#20732e;color:#fff;font-size:1.4rem}
table{width:100%;border-collapse:collapse;font-size:.9rem}
th,td{padding:8px 12px;white-space:nowrap;text-align:left}
tr:nth-child(even){background:#f5f5f5}
a{color:#1d5c9a;text-decoration:none}
.btn{display:inline-block;padding:4px 8px;border:1px solid #1d5c9a;
     border-radius:4px;font-size:.8rem}
.btn.del{border-color:#d11;color:#d11}
.msg{padding:12px;background:#e5ffd9;border-bottom:1px solid #c4f0b0}
.upload{padding:16px;border-bottom:1px solid #eee}
.upload input[type=file]{margin-bottom:8px}
</style>
<script>
function confirmDel(f){return confirm(f+' dosyasını silmek istediğinize emin misiniz?');}
</script></head><body><div class="box">
<h1>Arşiv</h1>

<?php if($msg): ?><div class="msg"><?=htmlspecialchars($msg)?></div><?php endif; ?>

<div class="upload">
  <form method="post" enctype="multipart/form-data">
    <input type="file" name="dosya" required>
    <button type="submit">Yükle</button>
    <small>• Maks <?=MAX_SIZE/1048576?> MB, yalnızca PDF/JPG/PNG</small>
  </form>
</div>

<table>
<thead><tr>
    <th>Dosya Adı</th><th>Boyut</th><th>Yüklenme</th>
    <th>İndir</th><th>Sil</th>
</tr></thead><tbody>
<?php if(!$files): ?>
<tr><td colspan="5" style="text-align:center">Dosya yok</td></tr>
<?php endif; foreach($files as $f): ?>
<tr>
    <td><a href="<?=rawurlencode($f)?>" target="_blank"><?=htmlspecialchars($f)?></a></td>
    <td><?=number_format(filesize($f)/1024,2,' ',',')?> KB</td>
    <td><?=date('d.m.y H:i:s',filemtime($f))?></td>
    <td>
        <a class="btn" href="<?=rawurlencode($f)?>" download>İndir</a>
    </td>
    <td>
        <a class="btn del"
           href="?action=delete&amp;f=<?=rawurlencode($f)?>"
           onclick="return confirmDel('<?=htmlspecialchars($f)?>')">Sil</a>
    </td>
</tr>
<?php endforeach; ?>
</tbody></table>

</div></body></html>
edit: indir button'u eklendi.