2

I want to stream an .wav audio file located in the application server directory, the file name should not be exposed to the end user. Im using Yii2 framework by the way, in general, how can I achieve this through PHP?

1
  • I think you can try a server rewrite module. Commented Sep 22, 2017 at 5:56

3 Answers 3

2

simple way. If you don't want to expose the file name then don't use name attribute.

<html>
<body>

<audio controls>
  <source src="horse.ogg" type="audio/ogg">
  <source src="horse.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>

</body>
</html>

src is the path of your audio file and type is the type of the audio.

Sign up to request clarification or add additional context in comments.

Comments

1

Actually I have managed to find a way to solve the problem.

Controller code

    $audioFilePath = "audio_file_absolute_path.wav"

    header('Cache-Control: no-cache');
    header('Content-Transfer-Encoding: binary');
    header('Content-Type: audio/wav'); // sets the output content type to wav
    header('Content-Length: ' . filesize($audioFilePath)); // sets the legth of the file (in order to the HTML5 player to access the audio duration)
    header('Accept-Ranges: bytes');
    header('Content-Disposition: inline; filename="test_audio.wav"'); // set an output file name

    readfile($audioFilePath); // reads the file 

View code (The audio player)

          <audio controls>
               <source id="audioPlayerSource" src="<? 'Url of audio file read controller function' ?>" type="audio/wav">
          </audio>

This way the audio file in the server gets streamed to the audio player in the view

Comments

0
<?php
    foreach($video as $video) { ?>
       <video width="100%" height="390" controls="">
           <source src="<?php echo $video['video'];?>" type="video/mp4">
       </video>
<?php } ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.