php导出csv,如下代码为什么不弹出提示保存或打开CSV文件?
functiondownload_csv(){$result=mysql_query("select*fromstudentorderbyidasc");$str="姓名...
function download_csv(){
$result = mysql_query("select * from student order by id asc");
$str = "姓名,性别,年龄\n";
$str = iconv('utf-8','gb2312',$str);
while($row=mysql_fetch_array($result)){
$name = iconv('utf-8','gb2312',$row['name']); //中文转码
$sex = iconv('utf-8','gb2312',$row['sex']);
$str .= $name.",".$sex.",".$row['age']."\n"; //用引文逗号分开
}
$filename = date('Ymd').'.csv'; //设置文件名
export_csv($filename,$str); //导出
}
function export_csv($filename,$data) {
header("Content-type:text/csv");
header("Content-Disposition:attachment;filename=".$filename);
header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
header('Expires:0');
header('Pragma:public');
echo $data;
} 展开
$result = mysql_query("select * from student order by id asc");
$str = "姓名,性别,年龄\n";
$str = iconv('utf-8','gb2312',$str);
while($row=mysql_fetch_array($result)){
$name = iconv('utf-8','gb2312',$row['name']); //中文转码
$sex = iconv('utf-8','gb2312',$row['sex']);
$str .= $name.",".$sex.",".$row['age']."\n"; //用引文逗号分开
}
$filename = date('Ymd').'.csv'; //设置文件名
export_csv($filename,$str); //导出
}
function export_csv($filename,$data) {
header("Content-type:text/csv");
header("Content-Disposition:attachment;filename=".$filename);
header('Cache-Control:must-revalidate,post-check=0,pre-check=0');
header('Expires:0');
header('Pragma:public');
echo $data;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询