Jsleshem Jsleshem - 1 year ago 61
HTML Question

Download Excel file from database in PHP

I have a MariaDB database on a site I am making. In this database, I have a bunch of Excel files that are available for download. For simplicity, lets say I have 5 files. The first named

, the second named
, and so on.

How can I force a download from the database if a user types the text
into a form, then clicks a button? Thanks!


Answer Source

To force the download of your file, link to downloadfile.php?filenum=num

This will be the code in downloadfile.php:

header('Content-Type: application/xls');
header('Content-Disposition: attachment; filename='.$_GET[filenum].'.xls');
header('Pragma: no-cache'); //if the file change, user will always download the last version
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download