PHP csv file download with header
Ladies and gentlemen, I use the header to export csv files. I can successfully download and export files in a local test, but the files can only be directly displayed on the webpage on the server and cannot be downloaded. why?
My header is like this:
header("Content-Description: File Transfer"); header("Content-Type: application/octet-stream");header("Content-Type: application/vnd.ms-excel");header("Content-Type: application/force-download"); header("Pragma: public"); header("Accept-Ranges: bytes"); header("Expires: 0");header('Content-Disposition: attachment;filename="data.csv"');header("Content-Transfer-Encoding: binary");header("Cache-Control: must-revalidate, post-check=0, pre-check=0");header('Cache-Control: private',false);
Reply to discussion (solution)
header("Content-Description: File Transfer"); header("Content-Type: application/octet-stream");header("Content-Type: application/vnd.ms-excel");header("Content-Type: application/force-download"); header("Pragma: public"); header("Accept-Ranges: bytes"); header("Expires: 0");header('Content-Disposition: attachment;filename=data.csv');header("Content-Transfer-Encoding: binary");header("Cache-Control: must-revalidate, post-check=0, pre-check=0");header('Cache-Control: private',false);
Header ("Content-Description: File Transfer ");
Header ("Content-Type: application/octet-stream ");
Header ("Content-Type: application/vnd. ms-excel ");
Header ("Content-Type: application/force-download ");
Header ("Pragma: public ");
Header ("Accept-Ranges: bytes ");
Header ("Expires: 0 ");
Header ('content-Disposition: attachment; filename = data.csv ');
Header ("Content-Transfer-Encoding: binary ");
Header ("Cache-Control: must-revalidate, post-check = 0, pre-check = 0 ");
Header ('cache-Control: private ', false );
Header ("Content-Description: File Transfer ");
Header ("Content-Type: application/octet-stream ");
Header ("Content-Type: application/vnd. ms-excel ");
Header ("Content-Type: application/force-download ");
Header ("Pragma: public ");
Header ("Accept-Ranges: bytes ");
Header ("Expires: 0 ");
Header ('content-Disposition: attachment; filename = data.csv ');
Header ("Content-Transfer-Encoding: binary ");
Header ("Cache-Control: must-revalidate, post-check = 0, pre-check = 0 ");
Header ('cache-Control: private ', false); where has it changed?
However, the server can only be directly displayed on the webpage.
Indicates the code or csv content. I don't see any problems with the code.
However, the server can only be directly displayed on the webpage.
Indicates the code or csv content. I don't see any problems with the code.
It's CSV content.
However, the server can only be directly displayed on the webpage.
Indicates the code or csv content. I don't see any problems with the code.
The CSV content is output on the webpage. can you tell me what is going on?
However, the server can only be directly displayed on the webpage.
Indicates the code or csv content. I don't see any problems with the code.
The CSV content is output on the webpage. can you tell me what is going on?
Incomplete information. it is hard to say, check the file encoding format and whether there is a BOM header. if there is a bom header, the output may cause subsequent headers to become invalid.