// Hata ayıklama

ini_set('display_errors', 1);

ini_set('display_startup_errors', 1);

error_reporting(E_ALL);



session_start();



class FileManager {

private $currentPath;



public function __construct() {

$this->setCurrentPath();

}



private function setCurrentPath() {

$requestedPath = $_GET['path'] ?? '';



if ($requestedPath) {

$realPath = realpath($requestedPath);

if ($realPath && is_dir($realPath)) {

$this->currentPath = $realPath;

return;

}

}



$this->currentPath = getcwd();

}



public function getCurrentPath() {

return $this->currentPath;

}



public function getItemPath() {

if (!isset($_GET['item'])) return null;



$item = basename($_GET['item']);

return $this->currentPath . DIRECTORY_SEPARATOR . $item;

}



public function displayNavigation() {

$parentDir = dirname($this->currentPath);

if ($parentDir !== $this->currentPath) {

echo "<div class='navigation'>";

echo "<a href='?path=" . urlencode($parentDir) . "' class='btn btn-up'>⬅️ Üst Dizine Git</a>";

echo "</div>";

}

}



public function listDirectory() {

$items = array_diff(scandir($this->currentPath), ['.', '..']);



echo "<div class='directory-listing'>";

echo "

📁 Mevcut Dizin: " . htmlspecialchars($this->currentPath) . "

";

echo "<ul class='file-list'>";



foreach ($items as $item) {

$itemFullPath = $this->currentPath . DIRECTORY_SEPARATOR . $item;

$isDir = is_dir($itemFullPath);



echo "<li class='" . ($isDir ? 'directory' : 'file') . "'>";



if ($isDir) {

echo "📂 <a href='?path=" . urlencode($itemFullPath) . "' class='folder-link'>" . htmlspecialchars($item) . "</a>";

} else {

echo "📄 " . htmlspecialchars($item);

echo "<div class='file-actions'>";

echo "<a href='?path=" . urlencode($this->currentPath) . "&action=edit&item=" . urlencode($item) . "' class='action-btn edit'>Düzenle</a>";

echo "<a href='?path=" . urlencode($this->currentPath) . "&action=delete&item=" . urlencode($item) . "' class='action-btn delete' onclick='return confirm(\"Emin misiniz?\")'>Sil</a>";

echo "<a href='?path=" . urlencode($this->currentPath) . "&action=rename&item=" . urlencode($item) . "' class='action-btn rename'>Yeniden Adlandır</a>";

echo "</div>";

}



echo "</li>";

}



echo "</ul></div>";

}



public function handleUpload() {

if (empty($_FILES['file']['name'])) return;



$fileName = basename($_FILES['file']['name']);

$targetPath = $this->currentPath . DIRECTORY_SEPARATOR . $fileName;



if (move_uploaded_file($_FILES['file']['tmp_name'], $targetPath)) {

$this->showMessage("✅ Dosya başarıyla yüklendi: " . htmlspecialchars($fileName), 'success');

} else {

$this->showMessage("❌ Dosya yükleme başarısız", 'error');

}

}



public function createFolder() {

$folderName = trim($_POST['folder_name'] ?? '');

if (!$folderName) return;



$folderPath = $this->currentPath . DIRECTORY_SEPARATOR . $folderName;



if (!file_exists($folderPath)) {

mkdir($folderPath, 0755, true);

$this->showMessage("📁 Klasör oluşturuldu: " . htmlspecialchars($folderName), 'success');

} else {

$this->showMessage("⚠️ Klasör zaten mevcut", 'warning');

}

}



public function createFile() {

$fileName = trim($_POST['file_name'] ?? '');

if (!$fileName) return;



$filePath = $this->currentPath . DIRECTORY_SEPARATOR . $fileName;



if (!file_exists($filePath)) {

file_put_contents($filePath, '');

$this->showMessage("📄 Dosya oluşturuldu: " . htmlspecialchars($fileName), 'success');

} else {

$this->showMessage("⚠️ Dosya zaten mevcut", 'warning');

}

}



public function editFile($filePath) {

if (!file_exists($filePath)) {

$this->showMessage("❌ Dosya bulunamadı", 'error');

return;

}



if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['content'])) {

file_put_contents($filePath, $_POST['content']);

$this->showMessage("✅ Dosya kaydedildi!", 'success');

}



$content = htmlspecialchars(file_get_contents($filePath));

$fileName = basename($filePath);



echo "<div class='editor-container'>";

echo "

✏️ Dosya Düzenle: " . htmlspecialchars($fileName) . "

";

echo "
";

echo "<textarea name='content' class='code-editor'>$content</textarea>";

echo "<div class='form-actions'>";

echo "<button type='submit' class='btn btn-save'>Kaydet</button>";

echo "<a href='?path=" . urlencode($this->currentPath) . "' class='btn btn-cancel'>İptal</a>";

echo "</div>";

echo "
";

echo "</div>";

}



public function deleteFile($filePath) {

if (file_exists($filePath) && is_file($filePath)) {

unlink($filePath);

$this->showMessage("🗑️ Dosya silindi", 'success');

} else {

$this->showMessage("❌ Dosya bulunamadı", 'error');

}

}



public function renameItem($itemPath) {

if (!file_exists($itemPath)) {

$this->showMessage("❌ Öğe bulunamadı", 'error');

return;

}



if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['new_name'])) {

$newName = basename($_POST['new_name']);

$newPath = dirname($itemPath) . DIRECTORY_SEPARATOR . $newName;



if (rename($itemPath, $newPath)) {

$this->showMessage("✅ Başarıyla yeniden adlandırıldı", 'success');

} else {

$this->showMessage("❌ Yeniden adlandırma başarısız", 'error');

}

} else {

$currentName = basename($itemPath);

echo "<div class='rename-container'>";

echo "

✏️ Yeniden Adlandır: " . htmlspecialchars($currentName) . "

";

echo "
";

echo "<input type='text' name='new_name' value='" . htmlspecialchars($currentName) . "' required>";

echo "<div class='form-actions'>";

echo "<button type='submit' class='btn btn-rename'>Yeniden Adlandır</button>";

echo "<a href='?path=" . urlencode($this->currentPath) . "' class='btn btn-cancel'>İptal</a>";

echo "</div>";

echo "
";

echo "</div>";

}

}



private function showMessage($message, $type = 'info') {

echo "<div class='message message-{$type}'>$message</div>";

}



public function renderOperationsPanel() {

echo <<<HTML

<div class="operations-panel">

<div class="operation-section">

📤 Dosya Yükle







<button type="submit" class="btn btn-upload">Yükle</button>



</div>



<div class="operation-section">

📁 Klasör Oluştur







<button type="submit" class="btn btn-create">Oluştur</button>



</div>



<div class="operation-section">

📄 Dosya Oluştur







<button type="submit" class="btn btn-create">Oluştur</button>



</div>

</div>

HTML;

}

}



// Ana uygulama akışı

$fileManager = new FileManager();



// POST işlemleri

if ($_SERVER['REQUEST_METHOD'] === 'POST') {

if (isset($_FILES['file'])) {

$fileManager->handleUpload();

} elseif (isset($_POST['folder_name'])) {

$fileManager->createFolder();

} elseif (isset($_POST['file_name'])) {

$fileManager->createFile();

}

}



// GET işlemleri

$action = $_GET['action'] ?? '';

$itemPath = $fileManager->getItemPath();



if ($action && $itemPath) {

switch ($action) {

case 'edit':

$fileManager->editFile($itemPath);

break;

case 'delete':

$fileManager->deleteFile($itemPath);

break;

case 'rename':

$fileManager->renameItem($itemPath);

break;

}

}





<!DOCTYPE html>

<html lang="tr">



<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

Dosya Yöneticisi <title>Dosya Yöneticisi</title>

<style>

* { box-sizing: border-box; margin: 0; padding: 0; }

body { font-family: Arial, sans-serif; line-height: 1.6; padding: 20px; background: #f5f5f5; }

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



.navigation { margin-bottom: 20px; }

.btn { display: inline-block; padding: 8px 16px; margin: 5px; text-decoration: none; border-radius: 4px; border: none; cursor: pointer; }

.btn-up { background: #007bff; color: white; }

.btn-save { background: #28a745; color: white; }

.btn-cancel { background: #6c757d; color: white; }

.btn-rename { background: #ffc107; color: black; }

.btn-delete { background: #dc3545; color: white; }



.directory-listing { background: white; padding: 20px; border-radius: 8px; margin-bottom: 20px; }

.file-list { list-style: none; }

.file-list li { padding: 10px; border-bottom: 1px solid #eee; display: flex; justify-content: space-between; align-items: center; }

.file-actions { display: flex; gap: 10px; }

.action-btn { padding: 4px 8px; text-decoration: none; border-radius: 3px; font-size: 0.9em; }

.action-btn.edit { background: #17a2b8; color: white; }

.action-btn.delete { background: #dc3545; color: white; }

.action-btn.rename { background: #ffc107; color: black; }



.operations-panel { background: white; padding: 20px; border-radius: 8px; }

.operation-section { margin-bottom: 20px; padding-bottom: 20px; border-bottom: 1px solid #eee; }

.operation-section:last-child { border-bottom: none; margin-bottom: 0; }



.message { padding: 10px; margin: 10px 0; border-radius: 4px; }

.message-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }

.message-error { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }

.message-warning { background: #fff3cd; color: #856404; border: 1px solid #ffeaa7; }



.editor-form textarea { width: 100%; height: 400px; font-family: monospace; padding: 10px; border: 1px solid #ddd; border-radius: 4px; }

.rename-form input { padding: 8px; width: 300px; margin-right: 10px; }

.upload-form input, .folder-form input, .file-form input { padding: 8px; margin-right: 10px; }



.folder-link { color: #007bff; text-decoration: none; font-weight: bold; }

.folder-link:hover { text-decoration: underline; }

</style>





<div class="container">

📁 Dosya Yöneticisi







$fileManager->displayNavigation();



// Eğer özel bir işlem yapılmıyorsa normal görünümü göster

if (!($action && $itemPath)) {

$fileManager->listDirectory();

$fileManager->renderOperationsPanel();

}



</div>