Viewing: " . htmlspecialchars($file) . "";
echo "" . htmlspecialchars(file_get_contents($file)) . "
";
echo "Back";
exit;
}
if ($action === 'edit' && $file && file_exists($file)) {
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
file_put_contents($file, $_POST['content']);
echo "Saved successfully.
";
}
echo "Editing: " . htmlspecialchars($file) . "
";
echo "";
echo "Back";
exit;
}
if ($action === 'delete' && $file && file_exists($file)) {
echo unlink($file) ? "Deleted." : "Failed.";
}
if ($action === 'rename' && $file && file_exists($file) && isset($_GET['new_name'])) {
$dir = dirname($file);
$newName = basename($_GET['new_name']);
$newPath = $dir . DIRECTORY_SEPARATOR . $newName;
if (!preg_match('/^[\w\-. ]+$/', $newName)) {
echo "Invalid filename.";
} elseif (file_exists($newPath)) {
echo "A file with that name already exists.";
} elseif (rename($file, $newPath)) {
echo "File renamed successfully.
Back";
exit;
} else {
echo "Rename failed.
";
}
}
if (!empty($_FILES['upload'])) {
$target = $currentDir . DIRECTORY_SEPARATOR . basename($_FILES['upload']['name']);
echo move_uploaded_file($_FILES['upload']['tmp_name'], $target)
? "Uploaded successfully."
: "Upload failed.";
}
echo "Index of " . htmlspecialchars($currentDir) . "
";
echo "
";
echo "";
$parent = dirname($currentDir);
if ($parent && $parent !== $currentDir) {
echo "- [ Parent Directory ]
";
}
foreach (scandir($currentDir) as $item) {
if ($item === '.' || $item === '..') continue;
$fullPath = $currentDir . DIRECTORY_SEPARATOR . $item;
$encoded = urlencode($fullPath);
$basename = htmlspecialchars($item);
if (is_dir($fullPath)) {
echo "- [DIR] $basename/
";
} else {
echo "- $basename";
echo " | View";
echo " | Edit";
echo " | Download";
echo " | Delete";
echo "
";
}
}
echo "
";
echo "
Logout";
if (isset($_GET['logout'])) {
session_destroy();
header("Location: " . $_SERVER['PHP_SELF']);
}
?>