Why wont the header() parse the pdf? It shows up as encripted with weird characters. If $type = 1, it is a pdf and i have to parse it with a PDF header, else if it is $type = 2 do something else.

My issue is with this header, does it have to appear on the first line on the page? how can i have a script switch out header() types for different types of content?

Code PHP:
<html>
<head>
</head>
<body>
<?php 
$type = $_GET['type']; 
 
if ( $_SESSION['valid_user'] ) 	{ 
 
	if ($type == "1"){
 
	$fileName = "pdf/filename.pdf";	
 
	header("Content-type: application/pdf");  
	readfile($fileName);
 
 
	} else if ($type == "2"){
	// DO THIS
 
 
} else { 
echo "You do not have permision to view this page";
}
?>
</body>
</html>