作者angelmark (湖畔風晴)
看板PHP
標題[請益] 使用header下載MP3 檔案都只有0K
時間Thu Sep 22 11:01:53 2011
各位大大
不好意思小弟又有問題要問了
在網路上找了很多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)
→ rocet:先確認 filesize($myFile) 的值正不正確 09/22 13:07
→ AndCycle:大小寫錯誤, myfile myFile 09/24 15:53
→ dlikeayu:開發時常有這問題,本身很喜歡用筆記本寫,後來放棄了 09/25 07:34
→ dlikeayu:有偵錯工具真的事半功倍 09/25 07:34