1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| <?php
public function httpHeader(){ $id = 21; $sql = "select pass from user where id=" . $id;
$pass = $mysql->getResult($sql); header("Content-type:text/plain");
header("Accept-Ranges:bytes");
header("Content-Disposition:attachement; filename=" . $pas . ".txt");
header("Cache-Control:must-revalidate,post-check=0,pre-check=0");
header("Pragma:no-cache");
echo $pass;
}
|
将生成的文件放到一个a链接中:
1
| <a href="/index/httpHeader">点击下载文件</a>
|
这样就可以简单的通过在线生成文件,不需要再存储到后台服务器。