Başarıyla giriş yaptınız!";
unset($_SESSION['login_success']);
}
// Fonksiyonlar
function getFileIcon($filename) {
$ext = strtolower(pathinfo($filename, PATHINFO_EXTENSION));
return match($ext) {
'jpg', 'jpeg', 'png', 'gif' => '🖼️',
'php', 'html', 'css', 'js', 'txt', '.htaccess', 'xml' => '💻',
'zip', 'rar' => '🗜️',
'pdf' => '📄',
'mp4', 'avi' => '🎞️',
'mp3' => '🎵',
default => '📄'
};
}
function recursiveDelete($path) {
if (is_dir($path)) {
foreach (scandir($path) as $item) {
if ($item !== '.' && $item !== '..') {
recursiveDelete($path . DIRECTORY_SEPARATOR . $item);
}
}
rmdir($path);
} elseif (is_file($path)) {
unlink($path);
}
}
function canCreate($path, $name, $isDir = false) {
$targetPath = $path . DIRECTORY_SEPARATOR . $name;
if (file_exists($targetPath)) {
if ($isDir && is_dir($targetPath)) {
return false;
}
if (!$isDir && is_file($targetPath)) {
return false;
}
}
return true;
}
// Dizin Güvenliği
$path = isset($_GET['path']) ? realpath($_GET['path']) : $baseDir;
if (!$path || strpos($path, $baseDir) !== 0) {
die("Erişim reddedildi.");
}
// POST İşlemleri
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['csrf_token']) && $_POST['csrf_token'] === $_SESSION['csrf_token']) {
$action = $_POST['action'] ?? '';
if ($action === 'upload' && isset($_FILES['file'])) {
$uploadPath = $path . DIRECTORY_SEPARATOR . basename($_FILES['file']['name']);
if (!file_exists($uploadPath)) {
move_uploaded_file($_FILES['file']['tmp_name'], $uploadPath);
echo "Dosya başarıyla yüklendi!
";
} else {
echo "Bu isimde bir dosya zaten var!
";
}
}
if ($action === 'create_folder' && !empty($_POST['folder_name'])) {
$folderName = preg_replace('/[^A-Za-z0-9_-]/', '_', $_POST['folder_name']);
$folderPath = $path . DIRECTORY_SEPARATOR . $folderName;
if (canCreate($path, $folderName, true)) {
if (!is_dir($folderPath)) {
mkdir($folderPath);
echo "Klasör oluşturuldu!
";
} else {
echo "Bu isimde klasör zaten var!
";
}
} else {
echo "Bu isimde bir öğe zaten var!
";
}
}
if ($action === 'create_file' && !empty($_POST['file_name'])) {
$fileName = preg_replace('/[^A-Za-z0-9._-]/', '_', $_POST['file_name']);
$filePath = $path . DIRECTORY_SEPARATOR . $fileName;
if (canCreate($path, $fileName, false)) {
if (!is_file($filePath)) {
file_put_contents($filePath, '');
echo "Dosya oluşturuldu!
";
} else {
echo "Bu isimde dosya zaten var!
";
}
} else {
echo "Bu isimde bir öğe zaten var!
";
}
}
if ($action === 'delete_selected' && !empty($_POST['selected'])) {
foreach ($_POST['selected'] as $key => $item) {
$targetPath = $path . DIRECTORY_SEPARATOR . $item;
if (file_exists($targetPath)) {
recursiveDelete($targetPath);
}
}
echo "Seçilenler silindi!
";
}
if ($action === 'rename_file' && !empty($_POST['old_name']) && !empty($_POST['new_name'])) {
foreach ($_POST['old_name'] as $key => $oldName) {
$newName = trim($_POST['new_name'][$key] ?? '');
$type = $_POST['type'][$key] ?? '';
if ($newName === '' || $oldName === '') continue;
$oldPath = $path . DIRECTORY_SEPARATOR . $oldName;
$newPath = $path . DIRECTORY_SEPARATOR . $newName;
if (($type === 'file' && is_file($oldPath)) || ($type === 'dir' && is_dir($oldPath))) {
if (!file_exists($newPath)) {
rename($oldPath, $newPath);
}
}
}
echo "Seçilenler yeniden adlandırıldı!
";
}
}
// Dosya Düzenleme İşlemi
if (isset($_GET['edit']) && is_file($path . DIRECTORY_SEPARATOR . $_GET['edit'])) {
$editFile = $path . DIRECTORY_SEPARATOR . $_GET['edit'];
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['content']) && isset($_POST['edit_csrf_token']) && $_POST['edit_csrf_token'] === $_SESSION['csrf_token']) {
file_put_contents($editFile, $_POST['content']);
echo "";
}
?>
Dosya Düzenle: = htmlspecialchars($_GET['edit']) ?>