I'm creating a portfolio website for my music and want to allow users to play my songs without them being able to see the source/download the mp3 files.
I'm using PHP for this project and loading the files via HTTP headers.
<?php
$mp3 ='72vox.mp3';
if(file_exists($mp3)) {
header('Content-Type: audio/mpeg');
header('Content-Disposition: inline; filename="mp3_file.mp3"');
header('Content-length: '. filesize($mp3));
header('Cache-Control: no-cache');
header('Content-Transfer-Encoding: chunked');
readfile($mp3);
exit;
}
?>
When the page loads, my mp3 plays. However, I can't seem to figure out how to display any HTML on the page (and more importantly, how to place the audio controls in a div).
Thank you for any help in advance
I'm creating a portfolio website for my music and want to allow users to play my songs without them being able to see the source/download the mp3 files.
That's impossible.
In this case, the URL of your PHP script is effectively the URL of the audio file.
When the page loads, my mp3 plays. However, I can't seem to figure out how to display any HTML on the page (and more importantly, how to place the audio controls in a div).
That has nothing to do with the way you serve the file. You need to make a page with an <audio>
tag, or with appropriate JavaScript. When you go to this URL, it's not a "page" from your server, it's just the browser's default handling of your MP3 file. Other browsers will just download it or open it up in the user's default audio player.