PHP Downloads Excel files,
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 formatting errors or corrupted files.
2, the output of Excel format must and suffix name to save all the time, no will prompt format error or file is corrupted
Copy 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 file ');
echo ' <script>alert (\ ' export error, File not exists! \ ') </script> ';
}