【发布时间】:2015-04-15 06:25:22
【问题描述】:
我参考了这些问题并实施了他们的答案,但没有一个对我有用。
download mp3 instead of playing in browser by default?
content type for mp3 download response
download mp3 from web url with android failed
基本上当用户点击网站上的下载链接时,我们希望用户被提示下载音频文件。
代码:
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Type: $mtype");
header("Content-Disposition: attachment; filename=".$file_name);
readfile($fname);
header("Content-Transfer-Encoding: binary");
header("Content-Length: " . $fsize);
这里,$mtype 是 "audio/mpeg"
成功:
- 它在所有桌面浏览器上都能正常工作。
- 我尝试使用 BlackBerry,并获得了下载的文件。
失败:
- 当我在安卓浏览器上做同样的事情时,我没有得到下载的文件。
- 文件名也丢失,带有
<untitled>并显示状态"download unsuccessful"。
感谢您知道为什么此代码无法在 Android 手机上运行。
【问题讨论】:
-
首先,在执行
readfile之前尝试发送标头。 -
@N.B.,我也尝试过,但没有成功。
标签: php android-browser