Hide audio url in PHP

浪子不回头ぞ 提交于 2019-12-24 11:31:23

问题


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...


回答1:


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);
}

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'>



来源:https://stackoverflow.com/questions/33581188/hide-audio-url-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!