PHP download Excel cannot open workaround _php tutorial

Source: Internet
Author: User
Tags php download
PHP download Excel file,
1, in the process of downloading do not output any non-file information, such as Echo log information. Otherwise, the downloaded file cannot be opened, prompting for incorrect formatting or corrupted file.
2, the output of the Excel format must be and the suffix name to save always, no will also prompt format error or file is corrupted

Copy the Code code as follows:
if (File_exists (Cache_path. $file _name)) {
$this->logger->error (' File Realpath: '. Realpath (Cache_path. $file _name));
Header (' Pragma:public ');
Header (' expires:0 ');
Header (' Content-encoding:none ');
Header (' Cache-control:must-revalidate, post-check=0, pre-check=0 ');
Header (' Cache-control:public ');
Header (' Content-type:application/vnd.ms-excel ');
Header (' Content-description:file Transfer ');
Header (' content-disposition:attachment; filename= '. $file _name);
Header (' content-transfer-encoding:binary ');
Header (' Content-length: ' FileSize (cache_path. $file _name));
ReadFile (Cache_path. $file _name);
} else {
$this->logger->error (' Export model: ' $id. ' ERROR: No production files ');
Echo ';
}

http://www.bkjia.com/PHPjc/621669.html www.bkjia.com true http://www.bkjia.com/PHPjc/621669.html techarticle php Download Excel file, 1, in the process of downloading do not output any non-file information, such as Echo log information. Otherwise the downloaded file cannot be opened, the prompt format is wrong or the file is broken ...

  • 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.