Problem downloading a php export

0

Good afternoon, I have a script that generates an excel spreadsheet with information, but after the exchange the server started to give problem, before it generated and dropped normally but now only saved on the server the file perfectly. But instead of downloading the file opens a page with coding defects. here is the part of the code that should be downloaded.

    header('Content-Type: application/vnd.ms-excel'); //mime type
    header('Content-Disposition: attachment;filename="'.$filename.'"'); //tell browser what's the file name
    header('Cache-Control: max-age=0'); //no cache
    readfile("download/".$filename);
    exit();
    
asked by anonymous 22.08.2018 / 20:41

1 answer

0

Use this form and it has worked.

// Configurações header para forçar o download
header ("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header ("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT");
header ("Cache-Control: no-cache, must-revalidate");
header ("Pragma: no-cache");
header ("Content-type: application/x-msexcel");
header ("Content-Disposition: attachment; filename=\"file.xls\"" );
header ("Content-Description: PHP Generated Data" );


// Envia o conteúdo do arquivo
echo $html;
exit; 
    
22.08.2018 / 21:36