Problem downloading a php export

Asked

Viewed 324 times

-1

Good afternoon, I have a script where generates an excel spreadsheet with information, but after the exchange of the server started to give problem, before it generated and downloaded normally but now just saved in the server the file perfectly. But instead of downloading the file opens a page with coding defects. follows below the part of the code that should bring the download.

    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();

1 answer

-1

Use that way and it’s 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; 
  • I tested the way it’s all white on the page.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.