[請益] header無法下載檔案

看板PHP作者 (上線專用)時間10年前 (2015/10/21 19:41), 編輯推噓0(005)
留言5則, 2人參與, 最新討論串1/1
請問各位 以下是我從網路上找到的標準範例, 不知哪邊錯誤,我的頁面都無法成功下載檔案呢。 PS. 確定檔案有產生 $handle = fopen("file.txt", "w"); fwrite($handle, "text1....."); fclose($handle); $url = "http://localhost/file.txt"; header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename('file.txt')); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize('file.txt')); readfile('file.txt'); exit; -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.43.97.245 ※ 文章網址: https://www.ptt.cc/bbs/PHP/M.1445427713.A.83B.html

10/21 21:18, , 1F
八成你目錄權限設不對
10/21 21:18, 1F

10/21 21:19, , 2F
用一個寫好的文字檔測試 不要像這樣先寫再輸出
10/21 21:19, 2F

10/21 21:19, , 3F
也不要想怎麼改權限 隨便改很危險 先把基本功練好
10/21 21:19, 3F

10/22 21:42, , 4F
謝謝MOON大~ 問題已順利解決
10/22 21:42, 4F

10/23 11:02, , 5F
很好…
10/23 11:02, 5F
文章代碼(AID): #1M9te1Wx (PHP)
文章代碼(AID): #1M9te1Wx (PHP)