Reputation:
I wrote PHP code to export data to .csv file.The exported .csv file was downloadable on my own PC. But in client's server, the .csv file was not downloadable, it was in readable format (the browser can read and print the file contents like a .html file).
Upvotes: 0
Views: 144
Reputation: 19372
Headers come first:
header('Content-Type: application/octet-stream');
header('Content-Transfer-Encoding: Binary');
header('Content-disposition: attachment; filename=members.csv');
$q = 'SELECT * FROM `members` ORDER BY `Mid` ASC';
$q = mysqli_query($connection, $q);
while ($record = mysqli_fetch_assoc($q)) :
echo $record['Member_Name'];
endwhile;
Upvotes: 1