Safari从PHP提供的mp3中提供了错误的音频持续时间
我正在向javascript播放器提供音频,例如(用于Safari): 我想为Safari设置正确的标题,以便他检索音频持续时间。我发现这个话题对我帮助很大: 我的PHP脚本'give_audio.PHP'是:Safari从PHP提供的mp3中提供了错误的音频持续时间,php,safari,header,mp3,html5-audio,Php,Safari,Header,Mp3,Html5 Audio,我正在向javascript播放器提供音频,例如(用于Safari): 我想为Safari设置正确的标题,以便他检索音频持续时间。我发现这个话题对我帮助很大: 我的PHP脚本'give_audio.PHP'是: if (isset($_GET['n']) && isset($_GET['t'])) { $n = htmlspecialchars($_GET['n']); $t = htmlspecialchars($_GET['t']); $filename =
if (isset($_GET['n']) && isset($_GET['t'])) {
$n = htmlspecialchars($_GET['n']);
$t = htmlspecialchars($_GET['t']);
$filename = $n.'.'.$t;
$path = 'Audio/'.$filename;
$fsize = filesize($path);
$shortlen = $fsize - 1;
$fp = fopen($path, 'r');
$etag = md5(serialize(fstat($fp)));
fclose($fp);
if ($t == 'mp3') $t = 'mpeg';
header("Pragma: public");
header("Expires: 0");
header('Cache-Control: no-cache, no-store');
header('Content-Transfer-Encoding: binary');
header('Content-Disposition: inline; filename="'.$filename.'"');
header('Content-Length: '.$fsize);
header('Content-Type: audio/'.$t);
header('Accept-Ranges: bytes');
header('Connection: Keep-Alive');
header('Content-Range: bytes 0-'.$shortlen.'/'.$fsize);
header('X-Pad: avoid browser bug');
header('Etag: '.$etag);
readfile($path);
} else {
header('HTTP/1.0 404 Not Found');
echo 'Error';
}
现在Safari找到了音频持续时间,但它是假的!它太长了,因此在结束时有几秒钟没有数据,这会阻碍玩家
此外,这在歌剧中不起作用
你有办法解决这个问题吗?我强烈建议提高安全性。仅基于
$\u GET
变量提供文件不是一种好的做法,这种方式用户只需更改GET请求即可从服务器检索任何文件。另外,不要将$\u GET
变量直接放入标题中。在实际使用变量之前,必须清理并验证所有$\u GET
变量!谢谢Anne,但由于我是新手,我不知道我在哪里制作新音频()
我可以发送$\u POST
变量。此外,我没有像对待htmlspecialchars
那样,将$\u GET
变量直接放在标题中。但这还不够吗?无论如何,标题仍然不起作用。我强烈建议提高安全性。仅基于$\u GET
变量提供文件不是一种好的做法,这种方式用户只需更改GET请求即可从服务器检索任何文件。另外,不要将$\u GET
变量直接放入标题中。在实际使用变量之前,必须清理并验证所有$\u GET
变量!谢谢Anne,但由于我是新手,我不知道我在哪里制作新音频()
我可以发送$\u POST
变量。此外,我没有像对待htmlspecialchars
那样,将$\u GET
变量直接放在标题中。但这还不够吗?无论如何,标题仍然不起作用。
if (isset($_GET['n']) && isset($_GET['t'])) {
$n = htmlspecialchars($_GET['n']);
$t = htmlspecialchars($_GET['t']);
$filename = $n.'.'.$t;
$path = 'Audio/'.$filename;
$fsize = filesize($path);
$shortlen = $fsize - 1;
$fp = fopen($path, 'r');
$etag = md5(serialize(fstat($fp)));
fclose($fp);
if ($t == 'mp3') $t = 'mpeg';
header("Pragma: public");
header("Expires: 0");
header('Cache-Control: no-cache, no-store');
header('Content-Transfer-Encoding: binary');
header('Content-Disposition: inline; filename="'.$filename.'"');
header('Content-Length: '.$fsize);
header('Content-Type: audio/'.$t);
header('Accept-Ranges: bytes');
header('Connection: Keep-Alive');
header('Content-Range: bytes 0-'.$shortlen.'/'.$fsize);
header('X-Pad: avoid browser bug');
header('Etag: '.$etag);
readfile($path);
} else {
header('HTTP/1.0 404 Not Found');
echo 'Error';
}