使用PHP在CSV文件中下载

I am trying to convert MySQL table to csv and download it from server. i have uploaded this script on server.

 <?php  
  //export.php  
 require 'db_connection.php';

 header('Content-Type: text/csv; charset=utf-8');  
 header('Content-Disposition: attachment; filename=data.csv');  
 $output = fopen("php://output", "w");  
 $sql = "select * from  tablaregistro";
 $stmt= $pdo->prepare($sql);
 $stmt->execute();
 while($row = $stmt->fetch())
 { 
    fputcsv($output, $row);  
 }  

 fclose($output);  
 ?>

This script is converting table to CSV and file is being downloaded in "data.csv" but when I upload this script to server, it is just displaying CSV on the whole page. It is not downloading like in localhost. I hope my question is clear.