I wrote PHP code to export data to
.csv file. The exported
.csv file was downloadable on my own PC. But in client's server, the
.csv file was not downloadable, it was in readable format (the browser can read and print the file contents like a
header() before accessing the
Is it a server side problem or do I need to change my code?
You need to send headers to tell the client what kind of file to expect and what to do with it.
header ('Content-Type: text/csv'); header ('Content-Disposition: attachment; filename="put_your_preferred_file_name_here.csv"');
You need to change the header sent by the server to let know to the browser that it need to download it instead of show it.
Add this to make the file being open by excel
or this for a more standard type
I very much liked this solution. In case the URL isn't reachable (any more):
.htaccess file into the same folder and add this line to it
AddType application/octet-stream .csv
that's all. (The original Link has some more file extensions, but this is the one for the OP).