php中csv文件的下載

使用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();{
}
相關文章
相關標籤/搜索