I am new to programming, just learning it at school, but i want my users download some excel files from my homepage. The following code isn't working, it only displays it in the browser and not forcing a download dialogue.
How can i solve this problem?
The link should be: http://myurl.com/download.php?fileid=1 or http://myurl.com/download.php?fileid=2 and so on.
<?php
switch ($_GET["fileid"]) {
case 0:
$file = "files/mon.xls";
break;
case 1:
$file = "files/uru2.xls";
break;
case 2:
$file = "files/oppo23.xls";
break;
}
readfile($file);
Thanks for your help!
You have to use header. Like you can read on the php manual, its for your file:
<?php
header('Content-type: application/xls');
header('Content-Disposition: attachment; filename="downloaded.xls"');
readfile($file);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With