title: PHPExcel save and retrieve MySql
body: <p>I am using PHPExcel to generate a spreadsheet.</p>
  
  <p>If I generate and download at the same time, everything is fine.</p>
  
  <p>But when I save to a MediumBlob in my MySQL and <em>then</em> download it, MSExcel says it is not ok.</p>
  
  <p>I am using the same headers in both situations.</p>
  
  <p>Gera is the function that generates the file:</p>
  
  <pre><code>$agora=date("Y-m-d H:i:s");
  
  $relatorio_rh_xls=$dbHandle-&gt;real_escape_string(RelatorioBaseRH::Gera($ciclo,$dbHandle));
  
  $qry="insert into tb_relatorio_rh (id_avaliacao_ciclo,relatorio_base_RH_xls,inicio_vigencia,fim_vigencia) values ( $ciclo,'".$relatorio_rh_xls."','".$agora."',null)";
  
  $result4=$dbHandle-&gt;query($qry);
  </code></pre>
  
  <p>And then to retrieve it:</p>
  
  <pre><code>$query = "SELECT $nomeRelatorio, OCTET_LENGTH($nomeRelatorio) as tamanho " .
                   "FROM tb_relatorio_rh WHERE id_avaliacao_ciclo = '$id_avaliacao_ciclo' and fim_vigencia is null order by inicio_vigencia desc";
  $resultadoConsulta= $dbHandle-&gt;query($query);
  
  $qtdeLinhas=$resultadoConsulta-&gt;num_rows;
          if ($qtdeLinhas&gt;0) {
              $fetBuscaRelatorio = $resultadoConsulta-&gt;fetch_assoc();
              $relatorio=$fetBuscaRelatorio[$nomeRelatorio];
              $size=$fetBuscaRelatorio['tamanho'];
  
  
              $type= substr($nomeRelatorio, -3, 3);
  
              if ($type == "xls"){ $type="xlsx";}
  
              $nomeAvaliado= str_replace(' ','_',$nomeAvaliado);
  
              $nomeDownload=substr($nomeRelatorio, 0, strlen($nomeRelatorio)-4) .'_' . $nomeAvaliado .'.'. $type;
  
              header("Content-Length: $size");
              header("Content-Type: $type");
              header("Content-Disposition: attachment; filename=$nomeDownload");
  
              print $relatorio;
  }
  </code></pre>