【问题标题】:php with mp3 header will not load (update/fixed)带有 mp3 标头的 php 将无法加载(更新/修复)
【发布时间】:2012-01-04 10:03:24
【问题描述】:

test.php 代码:

$fileloc = 'audio.mp3';
header('Content-type: audio/mpeg');
header("Content-disposition: inline; filename=$filename");
header('Content-Length:'.filesize($fileloc));

readfile($fileloc);

html代码:

<iframe src="test.php"></iframe>

这是正在运行的更新代码。

谢谢哈菲丘克

如果有人知道这样做的方法

<embed> or <object> rather than <iframe>

请分享您的代码或给我发送链接。

【问题讨论】:

  • this 在您的浏览器中工作吗?如果没有,您需要一个浏览器插件来播放声音。
  • 我在本地机器上测试了类似的东西,它可以工作 - 如果你将 ob_flush 更改为 ob_end_flush 以关闭输出缓冲怎么办?
  • 对不起,我错过了那个错字...我有flush()而不是ob_flush(),但我会尝试这些。
  • 您可以通过尝试下载文件并检查文件是否被传输来检查输出缓冲是否阻止文件被发送到输出。
  • 您正在加载的文件路径是一个 URL。 allow_url_fopen 设置是否启用?

标签: php html header mp3 embed


【解决方案1】:

尝试将您的内容类型更改为audio/mpeg3

更新 1:

由于它是作为附件下载文件,您也可以尝试将 content-disposition 更改为header('Content-Disposition: inline; filename=audio.mp3');

我为此找到的reference 用于嵌入标签中的swf 文件,但我想你也应该这样做。

【讨论】:

  • 我的建议是返回并查看非 php 版本的 embed 标签使用的 http 标头(请求和响应),看看是否有任何意外发生。我唯一能想到的是embed 使用范围标头,您的脚本可能需要这样做。
  • 您应该能够使用 Chrome 的“Inspect Element”或 Firefox 的 Firebug 插件来获取 http 标头。
  • 我无法使用 chrome 中的 inspect 元素查看太多内容,但我没有使用 ,而是使用了
【解决方案2】:

我知道这是旧的,但我找到了一个简单的方法来完成这个,但它可能不是最漂亮的,但是 在这里!

test.php:

<?php
if (isset($_GET['file'])) {
    echo file_get_contents('music.mp3');
    exit;
}
<audio src="test.php?file" controls></audio>

您只需使用 file_get_contents 提取文件并输出它,使用 php 文件作为声音文件,非常简洁:P

【讨论】:

    猜你喜欢
    • 2011-12-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-06-19
    • 1970-01-01
    • 2023-03-14
    • 2013-05-13
    • 2011-05-09
    相关资源
    最近更新 更多