[請益] 使用header下載MP3 檔案都只有 0 K

看板PHP作者 (湖畔風晴)時間12年前 (2011/09/22 11:01), 編輯推噓0(004)
留言4則, 3人參與, 最新討論串1/1
各位大大 不好意思小弟又有問題要問了 在網路上找了很多header下載MP3的方法 但是不管怎樣下載下來的資料都是 0 K 希望各位大大能夠幫幫小弟是不是程式碼哪邊寫錯了 程式碼如下: $filename="back.mp3"; $myfile = "/home/httpd/html/www.xxx.com/test/back.mp3"; $mm_type = "application/octet-stream"; header("Cache-Control: public, must-revalidate"); header("Pragma: hack"); header("Content-Type: " . $mm_type); header("Content-Length: " .(string)(filesize($myFile)) ); 這一段改寫成這樣結果也一樣 header("Content-Length: " .filesize($myFile)); header('Content-Disposition: attachment; filename="'.$filename.'"'); header("Content-Transfer-Encoding: binary"); readfile($myFile); 希望各位大大幫我看看是不是哪邊有問題 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 219.81.19.118 ※ 編輯: angelmark 來自: 219.81.19.118 (09/22 11:03) ※ 編輯: angelmark 來自: 219.81.19.118 (09/22 11:42)

09/22 13:07, , 1F
先確認 filesize($myFile) 的值正不正確
09/22 13:07, 1F

09/24 15:53, , 2F
大小寫錯誤, myfile myFile
09/24 15:53, 2F

09/25 07:34, , 3F
開發時常有這問題,本身很喜歡用筆記本寫,後來放棄了
09/25 07:34, 3F

09/25 07:34, , 4F
有偵錯工具真的事半功倍
09/25 07:34, 4F
文章代碼(AID): #1EUgKZRO (PHP)