PHP downloads files with headers

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.