I have audio located at /home/user/audio. I know it is impossible to prevent downloads, but I just want to make it tough for most. I followed this post: setting-up-apache-to-serve-php-when-an-mp3-file-is-requested
But people can still readily download the mp3 by selecting "Save Audio As" when right clicking the audio element.
Here is the code on the page where audio is linked:
$link="http://www.example.com/getaudio.php?name=$filename";
echo '<audio src="'.$link.'"' . ' autoplay controls>';
And here is the getaudio.php
$name=$_GET['name'];
$filename="/home/user/audio/".$name.".mp3";
if (file_exists($filename)) {
header("Content-Type: audio/mpeg");
header('Content-Length: ' . filesize($filename));
header('Content-Disposition: inline; filename="blah.mp3"');
header('X-Pad: avoid browser bug');
header('Cache-Control: no-cache');
readfile($filename);
exit;
} else {
header($_SERVER['SERVER_PROTOCOL'].' 404 Not Found', true, 404);
echo "no file";
}
Any idea why despite above, one can so easily download the mp3? In the linked example, I don't see anything obvious that I am missing, but I must be missing something obvious!
Edit: My post is different from the one mentioned, as I was trying to avoid a javascript approach, and instead use php, and disable the "save audio as" menu item. In the end though, I ended up using a single js line to disable the "save audio as" menu item as the audio element itself does not allow for that.
Thanks