I have used the code of download mysql data to csv in php.It works fine in localhost.when i click on export button it download the file in localhost in csv format but when i run this code on server and when i click export button it print the data it did not download the file.
<form method="post">
<input type="submit" name="export" value="export">
</form>
<?php
require 'db.php';
if(isset($_POST['export'])){
$q= mysql_query("select firstname,lastname,email from tab_Recruiter where status=1");
header('Content-Type: text/csv; charset=utf-8');
header('Content-Disposition: attachment; filename=Userinfo.csv');
header("Pragma: no-cache");
header("Expires: 0");
$data = fopen('php://output', 'w');
$first = true;
while($row = array_filter(mysql_fetch_assoc($q))){
if ($first) {
fputcsv($data, array_keys($row));
$first = false;
}
// fputcsv($fp, $row);
fputcsv($data, $row);
}
exit();
}
?>