看板 PHP 關於我們 聯絡資訊
※ 引述《johnney (You make me Complete!)》之銘言: : 我的作法是 : $saveasname = "test.csv"; : header('Content-Type: application/octet-stream'); : header('Content-Disposition: attachment; Filename="'.$saveasname.'"'); : 這一部份先丟在 script 的前面送出 header 後 : 後面再將要存入的內容 echo 出來即可 : 瀏覽器自動會出現下載的功能... 參考phpMyAdmin程式碼和自己以前實做的經驗,用在Gzip的壓縮下載 //檔名 $saveasname = "test.gz"; //Header設定 header('Content-Encoding:x-gzip'); header('Content-Type: application/x-gzip'); header('Content-Disposition: attachment; Filename="'.$saveasname.'"'); header('Pragma: no-cache'); //要輸出的內容用gzencode函式處理過 echo gzencode('hi', 9); ------------------------------------------------------------------- 以上程式很適合用在資料庫的備份上,因為文字檔可以壓縮非常小 如果有其他人知道更多header的用法或是原理也可以補充說明一下 這也是PHP應用很重要的部份 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 203.67.162.127
jikotw74:對啊 是否能說明一下上面header的意義?? 11/24 10:20
johnney:http://www.faqs.org/rfcs/rfc2616 11/24 10:37
ileadu:有普通的zip 方法嗎? 不是gzip的 11/27 20:36