php代碼段:php
public function httpHeader(){ $id = 21; $sql = "select pass from user where id=" . $id; $pass = $mysql->getResult($sql); //須要經獲取到的pass以文件形式,讓用戶能夠點擊下載到本地 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連接中:html
<a href="/index/httpHeader">點擊下載文件</a>
這樣就能夠簡單的經過在線生成文件,不須要再存儲到後臺服務器。mysql