title: Downloading excel file from controller in code igniter
body: <p>I am having the following issue: 
  I am using code igniter as php framework, and from one of my views I do an ajax call to a function that generates and xlsx file using PHPExcel and data from mysql database. The file is correctly created in the server but when I try to force_download it won't download anything. Here is the php function:</p>
  
  <pre><code>public function generar_excel($idCotizacion){
  
  isLogged($this-&gt;session-&gt;userdata('logged_in'));
  isAdmin($this-&gt;session-&gt;userdata('logged_in'));
  
  $cotizacion = $this-&gt;cotizacion_model-&gt;get_cotizacion_by_id($idCotizacion);
  
  $propuestas = $this-&gt;propuesta_model-&gt;getPropuestasPorCotizacion($idCotizacion);
  
  error_reporting(E_ALL);
  date_default_timezone_set('Europe/London');
  
  require_once 'application/libraries/PHPExcel-1.8/Classes/PHPExcel/IOFactory.php';
  require_once 'application/libraries/PHPExcel-1.8/Classes/PHPExcel.php';
  
  $excel2 = PHPExcel_IOFactory::createReader('Excel2007');
  $excel2 = $excel2-&gt;load('prueba.xlsx'); // Empty Sheet
  $excel2-&gt;setActiveSheetIndex(0);
  
  
  
  
  
  $excel2-&gt;getActiveSheet()-&gt;setCellValue('C8', $cotizacion["capitas"])
  -&gt;setCellValue('C2', $cotizacion["empresa_nombre"])
  -&gt;setCellValue('C9', $cotizacion["masa_salarial"])
  -&gt;setCellValue('B11', $cotizacion["aseguradora_actual"]) 
  -&gt;setCellValue('B13', $cotizacion["variable"]/100)   
  -&gt;setCellValue('B14', '0.6')    
  -&gt;setCellValue('B12', '0');
  
  
  
  
  
  $letra = 'C';
  
  foreach($propuestas-&gt;result_array() as $row) {
  
  
    $excel2-&gt;getActiveSheet()-&gt;setCellValue($letra.'11', $row["nombre"]) 
    -&gt;setCellValue($letra.'13', $row["variable"]/100)   
    -&gt;setCellValue($letra.'14', '0.6')    
    -&gt;setCellValue($letra.'12', '0')
    -&gt;setCellValue($letra.'16', '=C$8*'.$letra.'12+C$9*'.$letra.'13+C$8*'.$letra.'14')
    -&gt;setCellValue($letra.'17','=(B$16-'.$letra.'16)*13')
    -&gt;setCellValue($letra.'18','=1-('.$letra.'16/B16)');
    ++$letra;
  }
  
  
  $objWriter = PHPExcel_IOFactory::createWriter($excel2, 'Excel2007');
  $nombreArchivo = 'CuadroComparativo-'.$cotizacion["empresa_nombre"].'.xlsx';
  
  $objWriter-&gt;save('uploads/'.$nombreArchivo);
  $fileContents = file_get_contents('http://rpm.singleton.com.ar/uploads/'.$nombreArchivo);
  //print_r($fileContents);
  $this-&gt;load-&gt;helper('download');
  force_download($nombreArchivo, $fileContents);
  </code></pre>
  
  <p>}</p>
  
  <p>The response and preview from inspecting the browser are unreadable.
  Thank you!</p>