gpt4 book ai didi

php - 通过 php 流式传输 mp3 文件

转载 作者:可可西里 更新时间:2023-11-01 12:53:28 25 4
gpt4 key购买 nike

这是我通过 php 流式传输 mp3 文件的 php 代码

set_time_limit(0);
$dirPath = "path_of_the_directory";
$songCode = $_REQUEST['c'];
$filePath = $dirPath . "/" . $songCode . ".mp3";
$strContext=stream_context_create(
array(
'http'=>array(
'method'=>'GET',
'header'=>"Accept-language: en\r\n"
)
)
);
$fpOrigin=fopen($filePath, 'rb', false, $strContext);
header('content-type: application/octet-stream');
while(!feof($fpOrigin)){
$buffer=fread($fpOrigin, 4096);
echo $buffer;
flush();
}
fclose($fpOrigin);

它适用于 Mac Mini 和所有其他 PC,但不适用于 iPad 和 iPhone。甚至流媒体也适用于所有其他智能手机。您的帮助将不胜感激。

谢谢

最佳答案

如果是歌曲,为什么要content-type: application/octet-stream?更改标题:

set_time_limit(0);
$dirPath = "path_of_the_directory";
$songCode = $_REQUEST['c'];
$filePath = $dirPath . "/" . $songCode . ".mp3";
$strContext=stream_context_create(
array(
'http'=>array(
'method'=>'GET',
'header'=>"Accept-language: en\r\n"
)
)
);
$fpOrigin=fopen($filePath, 'rb', false, $strContext);
header('Content-Disposition: inline; filename="song.mp3"');
header('Pragma: no-cache');
header('Content-type: audio/mpeg');
header('Content-Length: '.filesize($filePath));
while(!feof($fpOrigin)){
$buffer=fread($fpOrigin, 4096);
echo $buffer;
flush();
}
fclose($fpOrigin);

LE:删除了 Content-Transfer-Encoding 并将 Content-Dispositionattachment 更改为 inline

关于php - 通过 php 流式传输 mp3 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14952157/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com