Exported file save on server. It should be downloaded in system without saving on server
<p>I have PHP script to exported record from database in to CSV file. When I click on export button, It creates a CSV file on server (current location). All data are properly being displayed in CSV file but It should not save on server, It should be downloaded in system. This question might be duplicate, but i didn't find answer.</p>

<p>Code for exported data in CSV file.</p>

<pre><code>$monthData  = mysql_query($query, $conn);
$columns_total = mysql_num_fields($monthData);

$output = "";

for ($i = 2; $i &lt; $columns_total; $i++) {
    $heading = mysql_field_name($monthData,$i);
    $output .= '"'.$heading.'",';
}
$output .="\n";

while ($row = mysql_fetch_array($monthData)) {
    for ($i = 2; $i &lt; $columns_total; $i++) {
        $output .='"'.$row["$i"].'",';
    }
    $output .="\n";
}
$fileName = $month.'Data.csv';
$csvfile = fopen($fileName, "w") or die("Unable to open file!");
fwrite($csvfile, $output);

fclose($csvfile);
</code></pre>

<p>As per my research or knowledge, I think there is a need to add some header (that specify fileName, fileSize and many other). I don't have much knowledge about it, why and where do i need to add it.</p>

<p>Can anyone help me out?</p>