使用header头部定义就可以,一下为阿拉蕾项目文件下载的部分代码:
$user_infos = “”;
if(!empty($download)) {
 header("Content-type:text/csv;charset=utf-8");
header("Content-Disposition:attachment;filename=player.csv");
header('Expires:0');
header('Pragma:no-cache');
$str = '"A","B","C","D","E"'."\r\n";
$str = iconv("utf-8","gb2312",$str);
echo $str;
foreach ($user_infos as $key=>$val) {
echo '"'.$val['zone'].'"';
echo ',"'.$val['sdk_id'].'"';
echo ',"'.$val['uid'].'"';
echo ',"'.$val['role_name'].'"';
echo ',"'.$val['vip'].'"';
echo ',"'.$val['last_ip'].'"'; echo "\r\n"; } exit();{
}