Download file created dynamically using PHP headers

I used this snippet to dynamically create some content and allow the user to download it as a file.

$fileContent = ".... Your Content ...";
$filename = "licenseFile.lic";
header("Content-Type: application/download");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Pragma: public");
header("Content-Disposition: attachment; filename=\"$filename\"");

echo $fileContent;
exit()
Advertisements

One thought on “Download file created dynamically using PHP headers

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s