"; } else { $uploadFilePath = $uploadDirectory . DIRECTORY_SEPARATOR . basename($_FILES['userfile']['name']); // Security: Implement file type checks, size checks, etc., here if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadFilePath)) { $uploadedFileName = htmlspecialchars(basename($_FILES["userfile"]["name"])); echo "The file $uploadedFileName has been uploaded.
"; //echo "File successfully uploaded.
"; // Provide a link to view/download the uploaded file $encodedFilePath = urlencode($uploadFilePath); echo "You can view or download the file.
"; } else { echo "File upload failed.
"; } } } echo "----------------------------------------------
"; echo "Directory contents of $directoryPath:
"; echo "----------------------------------------------
"; if ($handle = opendir($directoryPath)) { while (false !== ($entry = readdir($handle))) { if ($entry != "." && $entry != "..") { $entryPath = $directoryPath . DIRECTORY_SEPARATOR . $entry; $permissions = substr(sprintf('%o', fileperms($entryPath)), -3); $isAccessible = is_readable($entryPath) ? 'accessible' : 'denied'; if (is_dir($entryPath)) { echo "[Directory] $entry - chmod ($permissions) ($isAccessible)
"; } else { echo "[File] $entry - chmod ($permissions) ($isAccessible) - Download
"; } } } closedir($handle); } else { echo "Could not open the directory."; } ?>