php下載excel無法打開的解決方法
更新時間:2013年12月24日 09:54:06 作者:
php下載excel后無法打開的解決方法和注意事項,大家參考使用吧
php下載excel文件,
1、在下載的過程中不要 輸出任何非文件信息,比如 echo log信息。 否則下載后的文件無法打開,提示格式錯誤或者文件被破壞。
2、 輸出的excel格式一定要和后綴名保存一直,否也會提示格式錯誤或者文件被破壞
復(fù)制代碼 代碼如下:
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.' 錯誤:未生產(chǎn)文件');
echo '<script>alert(\'export error, file not exists!\')</script>';
}
您可能感興趣的文章:
- 原生PHP實現(xiàn)導(dǎo)出csv格式Excel文件的方法示例【附源碼下載】
- PHP實現(xiàn)實時生成并下載超大數(shù)據(jù)量的EXCEL文件詳解
- php導(dǎo)入導(dǎo)出excel實例
- 基于php導(dǎo)出到Excel或CSV的詳解(附utf8、gbk 編碼轉(zhuǎn)換)
- php將數(shù)據(jù)庫導(dǎo)出成excel的方法
- 使用PHPExcel實現(xiàn)數(shù)據(jù)批量導(dǎo)出為excel表格的方法(必看)
- PHP導(dǎo)出MySQL數(shù)據(jù)到Excel文件(fputcsv)
- PHP中ajax無刷新上傳圖片與圖片下載功能
- PHP使用ajax的post方式下載excel文件簡單示例
相關(guān)文章
ThinkPHP框架任意代碼執(zhí)行漏洞的利用及其修復(fù)方法
這篇文章主要介紹了ThinkPHP框架任意代碼執(zhí)行漏洞的利用及其修復(fù)方法,該漏洞的修復(fù)對于廣大使用ThinkPHP的開發(fā)人員來說尤為重要!需要的朋友可以參考下2014-07-07

