Tuesday, 28 January 2014

Use PHP to Force a File Download




<?php
header('Content-disposition: attachment; filename=huge_document.pdf');
header('Content-type: application/pdf');
readfile('huge_document.pdf');
?>

There should be no spaces or carriage returns anywhere in the file. Blank lines will cause PHP to default to text/html and your file won't download.


Share:

No comments:

Post a Comment