PHP输出非HTML格式文件

未分类 飞快学 278浏览
<?php     
header('Content-Description: File Transfer');     
header('Content-Type: application/octet-stream');     
header('Content-Disposition: attachment; filename=a.csv');     
header('Content-Transfer-Encoding: binary');     
header('Expires: 0');     
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');     
header('Pragma: public');     
ob_clean();     
flush();     
$rowarr=array(array('1','2','3'),array('1','2','3'));     
$fp=fopen('php://output', 'w');     
foreach($rowarr as $row){     
     fputcsv($fp, $row);     
}     
fclose($fp);     
exit;   
?>