Last Updated: February 25, 2016
·
2.246K
· anriettec

Simple PHP force-download for any MIME type

<?php
$file = $_GET['file'];
header("Content-disposition: attachment; filename=".$file);
header("Content-type: application/download");
readfile($file);

And that's it! Thank to this <a href="http://webdesign.about.com/od/php/ht/force_download.htm">How To Use PHP to Force a File Download</a> and this <a href="http://stackoverflow.com/questions/9511279/how-to-make-php-file-download">How to make php file download?</a> for the guidance.

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

PHP applications still send a browser full of JavaScript. Hardening the server does not inventory the payment, analytics, and plugin scripts that run after the HTML is delivered.

Security insights from Cside