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.
Written by Anriëtte
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
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
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#