user7714345
user7714345

Reputation:

csv/xls file not downloading in client server

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

Answers (1)

num8er
num8er

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

Related Questions