如何让动态生成的文件不存储在服务器上,让用户直接触发下载?

$str = "姓名,性别,年龄\n";
$str = iconv('utf-8','gb2312',$str);
  
$name = iconv('utf-8','gb2312', '张三');
$sex = iconv('utf-8','gb2312','男');
$str .= $name. "," . $sex . "," . '23' . "\n";
  
$name = iconv('utf-8','gb2312', '李四');
$sex = iconv('utf-8','gb2312','男');
$str .= $name. "," . $sex . "," . '23' . "\n";
  
$filename = date('Ymd').'.csv'; //设置文件名
  
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;




你可能感兴趣的:(如何让动态生成的文件不存储在服务器上,让用户直接触发下载?)