Can anyone help me to write code on PHP to download Excel File from the server.
I have created below codes using header
and readfile
but the downloaded file was corrupted.
//content type
header('Content-type: application/vnd.ms-excel');
//open/save dialog box
header('Content-Disposition: attachment; filename='.$fileName);
//read from server and write to buffer
readfile($reportPath);
Can anyone help me on the best way to download existing Excel file from the server.
Please see below image of data after downloaded
I suggest to use the X-SENDFILE header. https://tn123.org/mod_xsendfile/
I use something like the following:
Make sure you're not outputting anything before or after the readfile.
put that code before all header declaration