Codice PHP:
<?php
header("Content-disposition: attachment; filename=file.xls");
header("Content-type: application/vnd.ms-excel");
readfile("file.xls");
?>
Prova così. Non lasciare righe vuote nel codice.
In readfile() indica il percorso del file da scaricare.
Oppure in modo più esteso e completo, manda tutti gli header
Codice PHP:
$file ="file che vuoi scaricare";
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
In questo modo gli dici che il flusso dati sarà un file da salvare.