$con = mysql_connect('localhost','root','') or die('数据库连接失败!'); $db = mysql_select_db('test') or die('数据库选择失败!'); mysql_query('set names utf8'); $sql = 'select * from demo'; $f = fopen('info.txt','a+'); fwrite($f,'姓名|邮箱|手机号码'."\r\n"); $result = mysql_query($sql); $str = ''; while($res = mysql_fetch_array($result)){ $str .= $res['name'].'|'.$res['email'].'|'.$res['tel']."\r\n"; } fwrite($f,$str); fclose($f); header("Content-Type:application/force-download"); //强制下载保存 header("Content-Disposition:attachment;filename=info.txt");//保存文件名 readfile("info.txt"); //输出 unlink('info.txt');//保证第二次再下载时,没有重复数据,删除已生成的文件 |