How can PHP be used to redirect to a page that outputs a PDF file for download or viewing in a browser?

To redirect to a page that outputs a PDF file for download or viewing in a browser, you can use the header() function in PHP to set the content type to "application/pdf" and specify the filename. Then, use readfile() function to output the PDF file contents.

<?php
// Specify the PDF file path
$pdfFilePath = 'path/to/your/file.pdf';

// Set the appropriate headers
header('Content-Type: application/pdf');
header('Content-Disposition: inline; filename="file.pdf"');

// Output the PDF file
readfile($pdfFilePath);
exit;
?>