PHP uses headers to download files. I use headers to export csv files. I can test locally to download and export files, 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: PHP downloads files 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);
Download and share PHP csv files:
------ Solution --------------------
Reference:
Quote: reference:
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.