title: PHP code to download CSV file not working
body: <p>I have the below code, where I generate random numbers and try to download them as a CSV file.</p>
  
  <p>If I try the CSV code snippet alone on a different file it works, but in this code, it just does not work. I do see the random numbers echoed, but it does not download the CSV file.</p>
  
  <pre><code>&lt;?php
  
  $dataarray=array();
  
  function convert_to_csv($input_array, $output_file_name, $delimiter)
  {
  $temp_memory = fopen('php://memory', 'w');
  foreach ($input_array as $line) 
  {
  fputcsv($temp_memory, $line, $delimiter);
  }
  
  fseek($temp_memory, 0);
  header('Content-Type: application/csv');
  header('Content-Disposition: attachement; filename="' . $output_file_name . '";');
  fpassthru($temp_memory);
  }
  
  for ($i = 0; $i &lt;= 25000; $i++) 
  { 
    $num = (rand(50,110));
  
    array_push($dataarray,"$num");
  
    echo "Hearbeat #" .$i . "\t\t ------   " . $num;
    echo "&lt;br&gt;";
  }
  
  convert_to_csv($dataarray, 'data_as_csv.csv', ',');
  
  ?&gt;
  </code></pre>