title: Download csv file from PHP server
body: <p>I am writing a code to save my query output in csv file. It is getting saved in the csv file on the server. But how to download that file from the server on button click. I have written following code but it is not downloading thee file. Can any one help me out.</p>
  
  <p><strong>Code:-</strong></p>
  
  <pre><code>$group_result = mysql_query($selectquery, $conn);                                                   
  $fp = fopen('books.csv', 'w');
  header('Content-Type: application/csv; charset=UTF-8');
  header('Content-Disposition: attachment; filename="books.csv"');
  $filename = 'books.csv';
  while ($container_id_record = mysql_fetch_assoc($group_result)) {
  $i++;
  
  echo"&lt;tr class='gradeA odd' role='row'&gt;&lt;td class='sorting_1'&gt;" . $container_id_record['enquiry_date'] . "&lt;/td&gt;&lt;td&gt;" . $container_id_record['name'] . "&lt;/td&gt;&lt;td&gt;" .$container_id_record['mobile']. "&lt;/td&gt;&lt;td&gt;" . $container_id_record['program_name'] .  "&lt;/td&gt;&lt;td&gt;" . $container_id_record['schedule'] .  "&lt;/td&gt;&lt;td&gt;" . $container_id_record['shift'] .  "&lt;/td&gt;&lt;td&gt;" . $container_id_record['remark'] .  "&lt;/td&gt;";
  
  fputcsv($fp, $container_id_record);
  
  
  }
  
  fclose($fp);
  readfile($filename);
  </code></pre>