php下載excel檔案,
1、在下載的過程中不要 輸出任何非檔案資訊,比如 echo log資訊。 否則下載後的檔案無法開啟,提示格式錯誤或者檔案被破壞。
2、 輸出的excel格式一定要和尾碼名儲存一直,否也會提示格式錯誤或者檔案被破壞
複製代碼 代碼如下:
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.' 錯誤:未生產檔案');
echo '';
}
http://www.bkjia.com/PHPjc/621669.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/621669.htmlTechArticlephp下載excel檔案, 1、在下載的過程中不要 輸出任何非檔案資訊,比如 echo log資訊。 否則下載後的檔案無法開啟,提示格式錯誤或者檔案被破...