在PHP中隐藏音频网址 [英] Hide audio url in PHP
本文介绍了在PHP中隐藏音频网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在播放mp3
格式的音频,但是我想隐藏mp3网址.
我正在使用PHP
,但我尝试使用此代码,但他无法正常工作.
HTML
I am playing audio in mp3
format but I want to hide the mp3 url.
I'm using PHP
and I try this code but his is not working.
HTML
<audio controls>
<source src="mp3.php?id=1" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
PHP
<?php
$id = $_GET['id'];
if($id == 1){
echo '/path/to/audio.mp3';
}
?>
此代码的任何建议有什么问题.
我该怎么办.
谢谢...
What is wrong with this code any suggestion.
How can I do that.
Thanks...
推荐答案
未尝试过,但这可能有效:
Not tried, but this might work:
$filename = '/path/to/audio.mp3';
if(is_file($filename))
{
header('Content-Type: audio/mpeg');
header('Content-Disposition: inline;filename="'.basename($filename).'"');
header('Content-length: '.filesize($filename));
header('Cache-Control: no-cache');
header("Content-Transfer-Encoding: chunked");
readfile($filename);
}
基本上,我们在调用mp3.php的位置输出原始音频流.当我们说<img src='img.php'>
Basically we are outputting the raw audio stream in the location where mp3.php is called. This is also how we do it when we say <img src='img.php'>
这篇关于在PHP中隐藏音频网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文