• 03-06-2025, 22:06:40
    #1
    Değerli Arkadaşlarım;
    Gizli bir hostumuzda kendim için bir index sayafısı oluşturduk şirket içi dosyalarımızı paylaşmak gibi. Ancak buna upload bölümü ve sil bölümü eklemem lasım JSON MSQL gibi ekleme yapamıyoruz serverda engelleniyor o nedenle basit olması lazım tek index ile çözmemiz gerek bu konuda ekteki dosyamıza ilgi bölümlerin eklenmesi için destek olabilir misiniz? Minettar kalırım.

    index.php dosyası

  • 04-06-2025, 00:32:46
    #2
    <?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.
  • 04-06-2025, 08:55:22
    #3
    Barhalli adlı üyeden alıntı: mesajı görüntüle
    &lt;?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=&quot;Arşiv&quot;');
            header('HTTP/1.0 401 Unauthorized');  exit('Yetkisiz erişim!');
        }
    }
    
    /* --- 2) Silme -------------------------------------------------------------- */
    if (isset($_GET['action'], $_GET['f']) &amp;&amp; $_GET['action']==='delete') {
        $file = basename($_GET['f']);
        if ($file &amp;&amp; is_file($file)) { unlink($file); }
        header('Location: '.$_SERVER['PHP_SELF']); exit;
    }
    
    /* --- 3) Yükleme ------------------------------------------------------------ */
    $msg = '';
    if ($_SERVER['REQUEST_METHOD']==='POST' &amp;&amp; isset($_FILES['dosya'])) {
        $f = $_FILES['dosya'];
        if ($f['error']!==UPLOAD_ERR_OK)                $msg='Yükleme hatası: '.$f['error'];
        elseif ($f['size']&gt;MAX_SIZE)                   $msg='Dosya çok büyük (&gt;'.(MAX_SIZE/1048576).' MB)';
        elseif ($allowedMime &amp;&amp; !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)=&gt;
        is_file($f) &amp;&amp; $f!==$script                      // &lt;- index.php gizli
    );
    usort($files, fn($a,$b)=&gt;filemtime($b)&lt;=&gt;filemtime($a));
    
    /* --- 5) HTML --------------------------------------------------------------- */
    ?&gt;&lt;!doctype html&gt;&lt;html lang=&quot;tr&quot;&gt;&lt;head&gt;&lt;meta charset=&quot;utf-8&quot;&gt;
    &lt;title&gt;Arşiv&lt;/title&gt;
    &lt;style&gt;
    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}
    &lt;/style&gt;
    &lt;script&gt;
    function confirmDel(f){return confirm(f+' dosyasını silmek istediğinize emin misiniz?');}
    &lt;/script&gt;&lt;/head&gt;&lt;body&gt;&lt;div class=&quot;box&quot;&gt;
    &lt;h1&gt;Arşiv&lt;/h1&gt;
    
    &lt;?php if($msg): ?&gt;&lt;div class=&quot;msg&quot;&gt;&lt;?=htmlspecialchars($msg)?&gt;&lt;/div&gt;&lt;?php endif; ?&gt;
    
    &lt;div class=&quot;upload&quot;&gt;
      &lt;form method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt;
        &lt;input type=&quot;file&quot; name=&quot;dosya&quot; required&gt;
        &lt;button type=&quot;submit&quot;&gt;Yükle&lt;/button&gt;
        &lt;small&gt;• Maks &lt;?=MAX_SIZE/1048576?&gt; MB, yalnızca PDF/JPG/PNG&lt;/small&gt;
      &lt;/form&gt;
    &lt;/div&gt;
    
    &lt;table&gt;
    &lt;thead&gt;&lt;tr&gt;
        &lt;th&gt;Dosya Adı&lt;/th&gt;&lt;th&gt;Boyut&lt;/th&gt;&lt;th&gt;Yüklenme&lt;/th&gt;
        &lt;th&gt;İndir&lt;/th&gt;&lt;th&gt;Sil&lt;/th&gt;
    &lt;/tr&gt;&lt;/thead&gt;&lt;tbody&gt;
    &lt;?php if(!$files): ?&gt;
    &lt;tr&gt;&lt;td colspan=&quot;5&quot; style=&quot;text-align:center&quot;&gt;Dosya yok&lt;/td&gt;&lt;/tr&gt;
    &lt;?php endif; foreach($files as $f): ?&gt;
    &lt;tr&gt;
        &lt;td&gt;&lt;a href=&quot;&lt;?=rawurlencode($f)?&gt;&quot; target=&quot;_blank&quot;&gt;&lt;?=htmlspecialchars($f)?&gt;&lt;/a&gt;&lt;/td&gt;
        &lt;td&gt;&lt;?=number_format(filesize($f)/1024,2,' ',',')?&gt; KB&lt;/td&gt;
        &lt;td&gt;&lt;?=date('d.m.y H:i:s',filemtime($f))?&gt;&lt;/td&gt;
        &lt;td&gt;
            &lt;a class=&quot;btn&quot; href=&quot;&lt;?=rawurlencode($f)?&gt;&quot; download&gt;İndir&lt;/a&gt;
        &lt;/td&gt;
        &lt;td&gt;
            &lt;a class=&quot;btn del&quot;
               href=&quot;?action=delete&amp;amp;f=&lt;?=rawurlencode($f)?&gt;&quot;
               onclick=&quot;return confirmDel('&lt;?=htmlspecialchars($f)?&gt;')&quot;&gt;Sil&lt;/a&gt;
        &lt;/td&gt;
    &lt;/tr&gt;
    &lt;?php endforeach; ?&gt;
    &lt;/tbody&gt;&lt;/table&gt;
    
    &lt;/div&gt;&lt;/body&gt;&lt;/html&gt;
    edit: indir button'u eklendi.
    Barhalli adlı üyeden alıntı: mesajı görüntüle
    [SPOILER]
    <?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>
    [/SPOILER]
    [COLOR=initial][/COLOR]
    edit: indir button'u eklendi.
    Hocam Emekleriniz için çok çok teşekkür ederim sağolun
  • 09-06-2025, 09:22:04
    #4
    server ile alakalı bu sorun sorun klasör izinlerinde 777 olarak ayarlayın