force download file on users computer

This is how to use php to force a file to download onto the users computer.

 path to file
$file_name = 'blah_de_blah.png'; 
 force download 
if( file_exists($file_name)){
	$fsize = filesize($file_name);
	$path_parts = pathinfo($file_name);
	$ext = strtolower($path_parts["extension"]);

	 Determine Content Type
	switch ($ext) {
		case "pdf": $ctype="applicationpdf"; break;
		case "exe": $ctype="applicationoctet-stream"; break;
		case "zip": $ctype="applicationzip"; break;
		case "doc": $ctype="applicationmsword"; break;
		case "xls": $ctype="applicationvnd.ms-excel"; break;
		case "ppt": $ctype="applicationvnd.ms-powerpoint"; break;
		case "gif": $ctype="imagegif"; break;
		case "png": $ctype="imagepng"; break;
		case "jpeg":
		case "jpg": $ctype="imagejpg"; break;
		default: $ctype="applicationforce-download";
    }


	header("Pragma: public");  required
	header("Expires: 0");
	header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
	header("Cache-Control: private",false);  required for certain browsers
	header("Content-Type: $ctype");
	header("Content-Disposition: attachment; filename=\" . basename($file_name) . \";" );
	header("Content-Transfer-Encoding: binary");
	header("Content-Length: ".$fsize);
	ob_clean();
	flush();
	readfile( $file_name );
} else {
	die('File Not Found');
}