欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php下載excel無法打開的解決方法

 更新時(shí)間:2013年12月24日 09:54:06   作者:  
php下載excel后無法打開的解決方法和注意事項(xiàng),大家參考使用吧

php下載excel文件,
1、在下載的過程中不要 輸出任何非文件信息,比如 echo log信息。 否則下載后的文件無法打開,提示格式錯(cuò)誤或者文件被破壞。
2、 輸出的excel格式一定要和后綴名保存一直,否也會提示格式錯(cuò)誤或者文件被破壞

復(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.' 錯(cuò)誤:未生產(chǎn)文件');
      echo '<script>alert(\'export error, file not exists!\')</script>';
  }

相關(guān)文章

最新評論