Trigger the browser to download a file

From Knowledge Kitchen
Jump to navigation Jump to search


This example causes the browser to download a file. The hack is to set the "Content-type" HTTP header to be of a type that the browser is not able to parse.


<?php
	//send headers to the browser that trigger it to download this content instead of trying to display it.
	header("Content-type: application/nonsense");

	//send headers to the browser that specify the name of the file to be downloaded
	header('Content-Disposition: attachment; filename="free_healthcare.txt"');
?>

This is a text file that has no information of any use whatsoever.  Thanks for downloading it.


What links here