而不是生成.xls文件我得到.php文件在服务器端

我使用下面的头文件来使用PHP从数据库MySQL生成excel文件

header("Content-type: application/octet-stream"); header("Content-Type: application/vnd-ms-excel"); header("Content-disposition: attachments;filename=xxx.xls"); 

在本地输出是xxx.xls这是正确的文件,但在服务器端我越来越xxx.php文件(我正在使用一个cpanel帐户的ftp)家伙请帮助我的解决scheme

简单地使用

 header('Content-type: application/vnd.ms-excel'); header('Content-Disposition: attachment; filename="file.xls"'); 

只要你可以使用下面的PHP代码。 你必须给一个关键值对的数组

  $data = array("Name"=> "foo", "age" => 25); $filename = "My File Name" . date('Ymd') . ".xls"; header("Content-Disposition: attachment; filename=\"$filename\""); header("Content-Type: application/vnd.ms-excel"); $flag = false; foreach($data as $row) { if(!$flag) { // display field/column names as first row echo implode("\t", array_keys($row)) . "\n"; $flag = true; } foreach ($row as $value){ echo $value; echo "\t"; } echo "\n"; } exit;